diff --git a/.gitignore b/.gitignore index 7fb9d01..857fc43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,16 @@ +.DS_Store +.env + node_modules + tests/output examples/output -lib + local -.DS_Store -.env + +lib +pdf +svg +errors +types +utils \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index ad8aa3a..8dc06fb 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -7,7 +7,14 @@ export default [ ...sharedRules, { - ignores: ["src/shared/qr-code-generator.ts"] + ignores: [ + "src/shared/qr-code-generator.ts", + "pdf", + "svg", + "utils", + "types", + "errors" + ] }, { files: ["**/*.ts"], diff --git a/package.json b/package.json index dd9e138..2153adb 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,6 @@ }, "sideEffects": false, "exports": { - "./bundle": { - "require": "./lib/bundle/swissqrbill.js", - "import": "./lib/bundle/swissqrbill.js" - }, "./errors": { "require": { "types": "./lib/cjs/shared/errors.d.ts", @@ -55,12 +51,12 @@ "import": "./lib/esm/shared/utils.js" } }, - "main": "./lib/bundle/swissqrbill.js", "scripts": { "build": "npm run build:bundle && npm run build:cjs && npm run build:esm", "build:bundle": "vite build --config vite.config.bundle.ts", - "build:cjs": "vite build --config vite.config.cjs.ts && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", - "build:esm": "vite build --config vite.config.ts && echo '{ \"type\": \"module\" }' > lib/esm/package.json", + "build:cjs": "vite build --config vite.config.cjs.ts && node --experimental-strip-types scripts/cjs.ts", + "build:esm": "vite build --config vite.config.ts && node --experimental-strip-types scripts/esm.ts", + "clean": "rm -r ./pdf && rm -r ./svg && rm -r ./errors && rm -r ./types && rm -r ./utils", "docs": "npm run docs:pdf && npm run docs:svg && npm run docs:utils && npm run docs:errors && npm run docs:bundle", "docs:bundle": "unwritten src/bundle/index.ts -t tsconfig.docs.json -o docs/bundle/ ", "docs:errors": "unwritten src/shared/errors.ts -t tsconfig.docs.json -o docs/errors/", @@ -76,6 +72,8 @@ "markdownlint": "markdownlint-cli2 '**/*.md' '#node_modules'", "markdownlint:ci": "npm run markdownlint", "markdownlint:fix": "npm run markdownlint -- --fix", + "postbuild": "node --experimental-strip-types scripts/node10.ts", + "postpublish": "npm run clean", "postrelease:alpha": "npm run postrelease", "postrelease:beta": "npm run postrelease", "postrelease:latest": "eslint --fix package.json && markdownlint-cli2 --fix 'CHANGELOG.md'", @@ -100,7 +98,12 @@ "node": ">=18.0.0" }, "files": [ - "lib" + "lib", + "pdf", + "svg", + "errors", + "types", + "utils" ], "peerDependencies": { "pdfkit": ">=0.13.0", diff --git a/scripts/cjs.ts b/scripts/cjs.ts new file mode 100644 index 0000000..c3997ff --- /dev/null +++ b/scripts/cjs.ts @@ -0,0 +1,4 @@ +import { writeFileSync } from "node:fs"; + + +writeFileSync("lib/cjs/package.json", JSON.stringify({ type: "commonjs" }, null, 2)); diff --git a/scripts/esm.ts b/scripts/esm.ts new file mode 100644 index 0000000..826c478 --- /dev/null +++ b/scripts/esm.ts @@ -0,0 +1,4 @@ +import { writeFileSync } from "node:fs"; + + +writeFileSync("lib/esm/package.json", JSON.stringify({ type: "module" }, null, 2)); diff --git a/scripts/node10.ts b/scripts/node10.ts new file mode 100644 index 0000000..301bbc5 --- /dev/null +++ b/scripts/node10.ts @@ -0,0 +1,19 @@ +import { mkdirSync, writeFileSync } from "node:fs"; + + +const paths = { + errors: "cjs/shared/errors", + pdf: "cjs/pdf/index", + svg: "cjs/svg/index", + types: "cjs/shared/types", + utils: "cjs/shared/utils" +}; + +for(const dir in paths){ + const path = paths[dir]; + mkdirSync(dir, { recursive: true }); + writeFileSync(`${dir}/package.json`, JSON.stringify({ + main: `../lib/${path}.cjs`, + types: `../lib/${path}.d.ts` + }, null, 2)); +} diff --git a/tsconfig.json b/tsconfig.json index f9d4138..8fac992 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ }, "include": [ "src", + "scripts", "tests" ], "exclude": [