Skip to content

Commit

Permalink
fix: add node10 require fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Jan 1, 2025
1 parent d16f8cb commit 23aba4e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
15 changes: 12 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
.DS_Store
.env

node_modules

tests/output
examples/output
lib

local
.DS_Store
.env

lib
pdf
svg
errors
types
utils
9 changes: 8 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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/",
Expand All @@ -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'",
Expand All @@ -100,7 +98,12 @@
"node": ">=18.0.0"
},
"files": [
"lib"
"lib",
"pdf",
"svg",
"errors",
"types",
"utils"
],
"peerDependencies": {
"pdfkit": ">=0.13.0",
Expand Down
4 changes: 4 additions & 0 deletions scripts/cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { writeFileSync } from "node:fs";


writeFileSync("lib/cjs/package.json", JSON.stringify({ type: "commonjs" }, null, 2));
4 changes: 4 additions & 0 deletions scripts/esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { writeFileSync } from "node:fs";


writeFileSync("lib/esm/package.json", JSON.stringify({ type: "module" }, null, 2));
19 changes: 19 additions & 0 deletions scripts/node10.ts
Original file line number Diff line number Diff line change
@@ -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));
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"include": [
"src",
"scripts",
"tests"
],
"exclude": [
Expand Down

0 comments on commit 23aba4e

Please sign in to comment.