i18nsmith 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import { execSync } from 'node:child_process';
3
- import { mkdirSync, readFileSync, rmSync } from 'node:fs';
3
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
4
 
5
- const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
6
- const external = Object.keys(pkg.dependencies || {});
5
+ JSON.parse(readFileSync('./package.json', 'utf8'));
7
6
 
8
7
  console.log('Cleaning dist/');
9
8
  rmSync('dist', { recursive: true, force: true });
@@ -14,18 +13,29 @@ execSync('pnpm exec tsc -p tsconfig.json --emitDeclarationOnly', {
14
13
  stdio: 'inherit',
15
14
  });
16
15
 
17
- console.log('Bundling CLI with external dependencies:', external);
16
+ console.log('Bundling CLI as a single, self-contained CommonJS file (no externals)');
18
17
 
18
+ // Produce a single CommonJS bundle so `npx`/npm-installed binaries run consistently
19
+ // (some deps perform dynamic require() calls which fail under ESM bundles).
19
20
  await esbuild.build({
20
21
  entryPoints: ['src/index.ts'],
21
22
  bundle: true,
22
23
  platform: 'node',
23
- format: 'esm',
24
+ format: 'cjs', // CommonJS output avoids ESM dynamic-require limitations
24
25
  target: ['node18'],
25
- outfile: 'dist/index.js',
26
- external,
26
+ outfile: 'dist/index.cjs',
27
+ // Produce a self-contained bundle for npx installs
28
+ external: [],
27
29
  sourcemap: false,
28
30
  minify: false,
29
31
  });
30
32
 
31
- console.log('CLI bundle built at dist/index.js');
33
+ // Add shebang was above to make the CJS bundle executable when installed via npm/npx
34
+ // (esbuild supports banner to prepend text).
35
+ console.log('CLI bundle built at dist/index.cjs (CommonJS)');
36
+
37
+ // Emit a small ESM shim that forwards imports to the CJS bundle. This satisfies
38
+ // `exports.import` consumers while keeping the runtime CLI as CommonJS.
39
+ const shim = `import { createRequire } from 'module';\nconst require = createRequire(import.meta.url);\nconst cjs = require('./index.cjs');\nexport default cjs;\nfor (const k of Object.keys(cjs)) { try { Object.defineProperty(exports, k, { enumerable: true, get: () => cjs[k] }); } catch (e) {} }\n`;
40
+ writeFileSync('dist/index.js', shim, 'utf8');
41
+ console.log('ESM shim written to dist/index.js');