Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92b5fd92bc | ||
|
|
d486655f54 |
+4
-4
@@ -5,16 +5,16 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "barrelsby --directory src --delete --single",
|
"prebuild": "barrelsby --directory src --delete --single",
|
||||||
"build:esm": "tsc -p tsconfig.esm.json",
|
"build:esm": "tsc -p tsconfig.esm.json && node scripts/postbuild-esm.cjs",
|
||||||
"build:cjs": "tsc -p tsconfig.cjs.json",
|
"build:cjs": "tsc -p tsconfig.cjs.json && find dist/cjs -name \"*.js\" -type f -exec sh -c 'mv \"$1\" \"${1%.js}.cjs\"' _ {} \\; && node scripts/postbuild.cjs",
|
||||||
"build": "npm run prebuild && npm run build:esm && npm run build:cjs",
|
"build": "rm -rf dist && npm run prebuild && npm run build:esm && npm run build:cjs",
|
||||||
"lint": "eslint ."
|
"lint": "eslint ."
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/types/index.d.ts",
|
"types": "./dist/types/index.d.ts",
|
||||||
"import": "./dist/esm/index.js",
|
"import": "./dist/esm/index.js",
|
||||||
"require": "./dist/cjs/index.js"
|
"require": "./dist/cjs/index.cjs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"types": "./dist/types/index.d.ts",
|
"types": "./dist/types/index.d.ts",
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Recursively process all .js files in esm directory
|
||||||
|
function processDirectory(dir) {
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = path.join(dir, file);
|
||||||
|
const stat = fs.statSync(filePath);
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
processDirectory(filePath);
|
||||||
|
} else if (file.endsWith('.js')) {
|
||||||
|
// Read the file
|
||||||
|
let content = fs.readFileSync(filePath, 'utf8');
|
||||||
|
|
||||||
|
// Replace import/export statements to add .js extension
|
||||||
|
// Replace from "./path" with from "./path.js" (for relative imports only)
|
||||||
|
content = content.replace(/from ["'](\.[^"']*?)(?<!\.js)["']/g, 'from "$1.js"');
|
||||||
|
|
||||||
|
// Write back
|
||||||
|
fs.writeFileSync(filePath, content, 'utf8');
|
||||||
|
console.log(`✓ Updated ${filePath}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
processDirectory('./dist/esm');
|
||||||
|
console.log('✓ ESM post-build processing complete');
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Recursively process all .cjs files
|
||||||
|
function processDirectory(dir) {
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = path.join(dir, file);
|
||||||
|
const stat = fs.statSync(filePath);
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
processDirectory(filePath);
|
||||||
|
} else if (file.endsWith('.cjs')) {
|
||||||
|
// Read the file
|
||||||
|
let content = fs.readFileSync(filePath, 'utf8');
|
||||||
|
|
||||||
|
// Replace require statements to add .cjs extension
|
||||||
|
content = content.replace(/require\("([^"]*?)(?<!\.cjs)"\)/g, 'require("$1.cjs")');
|
||||||
|
|
||||||
|
// Write back
|
||||||
|
fs.writeFileSync(filePath, content, 'utf8');
|
||||||
|
console.log(`✓ Updated ${filePath}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
processDirectory('./dist/cjs');
|
||||||
|
console.log('✓ Post-build processing complete');
|
||||||
+4
-12
@@ -1,15 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "./tsconfig.base.json",
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"noEmit": true
|
||||||
"declaration": true,
|
}
|
||||||
"declarationMap": true,
|
|
||||||
"outDir": "./dist",
|
|
||||||
"module": "CommonJS",
|
|
||||||
"target": "ES2022",
|
|
||||||
"moduleResolution": "Node",
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"ignoreDeprecations": "6.0"
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user