55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
// Copyright 2024 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
// Optimizes package.json for npm publishing
|
|
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
const root = path.resolve(__dirname, '..')
|
|
const source = 'package.json'
|
|
const dest = 'package-main.json'
|
|
const _pkgJson = JSON.parse(fs.readFileSync(path.join(root, source), 'utf-8'))
|
|
|
|
const whitelist = new Set([
|
|
'name',
|
|
'version',
|
|
'description',
|
|
'type',
|
|
'main',
|
|
'types',
|
|
'typesVersions',
|
|
'exports',
|
|
'bin',
|
|
'man',
|
|
'files',
|
|
'engines',
|
|
'optionalDependencies',
|
|
'publishConfig',
|
|
'keywords',
|
|
'repository',
|
|
'homepage',
|
|
'author',
|
|
'license',
|
|
])
|
|
|
|
const pkgJson = Object.fromEntries(
|
|
Object.entries(_pkgJson).filter(([k]) => whitelist.has(k))
|
|
)
|
|
|
|
fs.writeFileSync(path.resolve(root, dest), JSON.stringify(pkgJson, null, 2))
|
|
|
|
console.log(`${dest} prepared for npm`)
|