-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): incorrect behaviors (#1626)
* fix(cli): target selector is not available in interactive mode * fix(cli): js binding file should export * fix(cli): wrong node engine requirements syntax * feat(cli): support esm module * restore js binding implementation in v2 --------- Co-authored-by: LongYinan <lynweklm@gmail.com>
- Loading branch information
1 parent
b34cca4
commit fb22a5a
Showing
14 changed files
with
154 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,68 @@ | ||
import { CommonPackageJsonFields } from '../../utils/config.js' | ||
|
||
export const createPackageJson = ({ | ||
name, | ||
binaryName, | ||
targets, | ||
license, | ||
engineRequirement, | ||
cliVersion, | ||
esm, | ||
}: { | ||
name: string | ||
binaryName: string | ||
targets: string[] | ||
license: string | ||
engineRequirement: string | ||
cliVersion: string | ||
esm: boolean | ||
}) => { | ||
return `{ | ||
"name": "${name}", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"license": "${license}", | ||
"engines": { | ||
"node": "${engineRequirement}" | ||
}, | ||
"napi": { | ||
"binaryName": "${binaryName}", | ||
"targets": [ | ||
${targets.map((t) => `"${t}"`).join(',\n ')} | ||
] | ||
}, | ||
"scripts": { | ||
"test": "node -e \\"assert(require('.').sum(1, 2) === 3)\\"", | ||
"build": "napi build --release --platform --strip", | ||
"build:debug": "napi build", | ||
"prepublishOnly": "napi prepublish -t npm", | ||
"artifacts": "napi artifacts", | ||
"version": "napi version" | ||
}, | ||
"devDependencies": { | ||
"@napi-rs/cli": "^${cliVersion}" | ||
const content: CommonPackageJsonFields = { | ||
name, | ||
version: '1.0.0', | ||
license, | ||
engines: { | ||
node: engineRequirement, | ||
}, | ||
type: 'commonjs', | ||
main: 'index.js', | ||
types: 'index.d.ts', | ||
module: undefined, | ||
exports: undefined, | ||
napi: { | ||
binaryName, | ||
targets, | ||
}, | ||
scripts: { | ||
test: 'node -e "assert(require(\'.\').sum(1, 2) === 3)"', | ||
build: 'napi build --release --platform --strip', | ||
'build:debug': 'napi build', | ||
prepublishOnly: 'napi prepublish -t npm', | ||
artifacts: 'napi artifacts', | ||
version: 'napi version', | ||
}, | ||
devDependencies: { | ||
'@napi-rs/cli': `^${cliVersion}`, | ||
}, | ||
} | ||
}` | ||
|
||
if (esm) { | ||
content.type = 'module' | ||
content.main = 'index.cjs' | ||
content.module = 'index.js' | ||
content.exports = { | ||
'.': { | ||
import: { | ||
default: './index.js', | ||
types: './index.d.ts', | ||
}, | ||
require: { | ||
default: './index.cjs', | ||
types: './index.d.ts', | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
return JSON.stringify(content, null, 2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.