Converted package scripts and config to compile in both CJS and ESM

This commit is contained in:
Alexander Cerutti
2025-01-11 14:40:56 +01:00
parent d6351f15c1
commit 2bbea853e7
5 changed files with 60 additions and 10 deletions

View File

@@ -2,11 +2,13 @@
"name": "passkit-generator", "name": "passkit-generator",
"version": "3.2.0", "version": "3.2.0",
"description": "The easiest way to generate custom Apple Wallet passes in Node.js", "description": "The easiest way to generate custom Apple Wallet passes in Node.js",
"main": "lib/index.js", "main": "lib/cjs/index.js",
"types": "lib/types/index.d.ts",
"type": "module",
"scripts": { "scripts": {
"build": "pnpm build:src", "build": "rm -rf lib && pnpm tsc -b tsconfig.esm.json tsconfig.cjs.json && pnpm build:dual",
"build:all": "pnpm build:src && pnpm build:examples", "build:dual": "pnpm tsconfig-to-dual-package tsconfig.esm.json tsconfig.cjs.json",
"build:src": "pnpm rimraf lib && pnpm tsc -p tsconfig.dist.json", "build:all": "pnpm build && pnpm build:examples",
"prepublishOnly": "pnpm build && pnpm test", "prepublishOnly": "pnpm build && pnpm test",
"test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" pnpm jest -c jest.config.cjs --silent" "test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" pnpm jest -c jest.config.cjs --silent"
}, },
@@ -38,9 +40,17 @@
"jest-environment-node": "^29.7.0", "jest-environment-node": "^29.7.0",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"rimraf": "^4.4.1", "rimraf": "^4.4.1",
"tsconfig-to-dual-package": "^1.2.0",
"typescript": "^5.6.3" "typescript": "^5.6.3"
}, },
"files": [ "files": [
"lib/**/*.+(js|d.ts)" "lib/**/*.+(js|d.ts)"
] ],
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js"
}
}
} }

25
pnpm-lock.yaml generated
View File

@@ -45,6 +45,9 @@ importers:
rimraf: rimraf:
specifier: ^4.4.1 specifier: ^4.4.1
version: 4.4.1 version: 4.4.1
tsconfig-to-dual-package:
specifier: ^1.2.0
version: 1.2.0(typescript@5.6.3)
typescript: typescript:
specifier: ^5.6.3 specifier: ^5.6.3
version: 5.6.3 version: 5.6.3
@@ -1068,6 +1071,12 @@ packages:
resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==}
engines: {node: '>=8'} engines: {node: '>=8'}
resolve-tsconfig@1.3.0:
resolution: {integrity: sha512-Ba5mo3soshb2CnIcNFz75F/80H/2eMVxrlmdgoSDNH7Lr6UAoT3BvxNtc7+VXqKSBlC0SJk2qSXOTcy0/p7cFw==}
engines: {node: '>=16', pnpm: '>=7'}
peerDependencies:
typescript: '*'
resolve.exports@2.0.2: resolve.exports@2.0.2:
resolution: {integrity: sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg==} resolution: {integrity: sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg==}
engines: {node: '>=10'} engines: {node: '>=10'}
@@ -1177,6 +1186,13 @@ packages:
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
engines: {node: '>=8.0'} engines: {node: '>=8.0'}
tsconfig-to-dual-package@1.2.0:
resolution: {integrity: sha512-UtMinqTLfWr9fX6KidLsEcCJoA/jSLPIS00ohpQybMSxA3LlJCRf2DsGPw4AJJ8AP4FOHfbQJFJ5XgLoL7RoLw==}
engines: {node: '>=18.3.0 || >=16.17.0'}
hasBin: true
peerDependencies:
typescript: '>=4.0.0'
tslib@2.7.0: tslib@2.7.0:
resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==} resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==}
@@ -2549,6 +2565,10 @@ snapshots:
resolve-from@5.0.0: {} resolve-from@5.0.0: {}
resolve-tsconfig@1.3.0(typescript@5.6.3):
dependencies:
typescript: 5.6.3
resolve.exports@2.0.2: {} resolve.exports@2.0.2: {}
resolve@1.22.8: resolve@1.22.8:
@@ -2639,6 +2659,11 @@ snapshots:
dependencies: dependencies:
is-number: 7.0.0 is-number: 7.0.0
tsconfig-to-dual-package@1.2.0(typescript@5.6.3):
dependencies:
resolve-tsconfig: 1.3.0(typescript@5.6.3)
typescript: 5.6.3
tslib@2.7.0: {} tslib@2.7.0: {}
type-detect@4.0.8: {} type-detect@4.0.8: {}

11
tsconfig.cjs.json Normal file
View File

@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "lib/cjs",
"inlineSourceMap": true,
"skipLibCheck": true,
"module": "CommonJS",
"moduleResolution": "Node10"
},
"include": ["src/**/*"]
}

View File

@@ -1,10 +1,11 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "lib", "outDir": "lib/esm",
"declaration": true,
"inlineSourceMap": true, "inlineSourceMap": true,
"skipLibCheck": true "skipLibCheck": true,
"module": "Node16",
"moduleResolution": "Node16"
}, },
"include": ["src/**/*"] "include": ["src/**/*"]
} }

View File

@@ -1,11 +1,14 @@
{ {
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "declaration": true,
"declarationDir": "lib/types",
"target": "es2018", "target": "es2018",
"esModuleInterop": true, "esModuleInterop": true,
"newLine": "LF", "newLine": "LF",
"importHelpers": true, "importHelpers": true,
"useUnknownInCatchVariables": true "useUnknownInCatchVariables": true,
"moduleResolution": "Node16",
"module": "Node16"
}, },
"exclude": ["node_modules/"] "exclude": ["node_modules/"]
} }