diff --git a/package.json b/package.json index 4eb569f..074145d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@personnummer/generate", - "version": "1.0.2", + "version": "1.0.3", "description": "Generate Swedish Personal Identity Numbers", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", @@ -10,7 +10,7 @@ "url": "git://github.com/personnummer/js-generate.git" }, "files": [ - "dist" + "dist/**/*" ], "scripts": { "build": "pine build", diff --git a/pinefile.js b/pinefile.js index be7c835..3d31ba4 100644 --- a/pinefile.js +++ b/pinefile.js @@ -1,14 +1,33 @@ import { run, log, series } from '@pinefile/pine'; import isCI from 'is-ci'; -import { build } from 'esbuild'; +import { build as esbuild } from 'esbuild'; +import fs from 'fs'; const buildOptions = (format) => ({ entryPoints: ['./src/index.ts'], bundle: true, format, outfile: `./dist/${format}/index.js`, + write: false, }); +const build = async (options) => { + fs.mkdirSync(`./dist/${options.format}`); + + const result = await esbuild(options); + + for (let out of result.outputFiles) { + fs.writeFileSync( + out.path, + options.format === 'cjs' + ? // fixes #468 + out.text.replace('module.exports = __toCommonJS(src_exports);', '') + + 'module.exports = src_default;' + : out.text + ); + } +}; + export default { build: async () => { await run('rimraf dist'); diff --git a/test.ts b/test.ts index c806691..0756701 100644 --- a/test.ts +++ b/test.ts @@ -1,7 +1,7 @@ import personnummer from 'personnummer'; const lib = require(process.env.FILE); -const generate = lib.default ? lib.default : lib; +const generate = process.env.FILE?.includes('esm') ? lib.default : lib; const padZero = (i: number): string => (i < 10 ? `0${i}` : `${i}`);