From 6ef503434be1479a2a0ef4b9861546ff65830468 Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Fri, 3 Jan 2025 12:40:42 +0100 Subject: [PATCH] version 3.x --- .eslintrc.cjs | 9 ----- .github/workflows/ci.yml | 51 +++++++++++++++++++++++++ .gitignore | 1 + README.md | 13 +++---- build.js | 78 --------------------------------------- build.ts | 1 + eslint.config.mjs | 1 + package.json | 36 +++++++++++------- sonar-project.properties | 9 +++++ src/build.ts | 80 ++++++++++++++++++++++++++++++++++++++++ tsconfig.cjs.json | 7 ---- tsconfig.eslint.json | 7 ++++ tsconfig.esm.json | 7 ---- tsconfig.json | 3 +- tsconfig.types.json | 8 ---- 15 files changed, 180 insertions(+), 131 deletions(-) delete mode 100644 .eslintrc.cjs create mode 100644 .github/workflows/ci.yml delete mode 100644 build.js create mode 120000 build.ts create mode 100644 eslint.config.mjs create mode 100644 sonar-project.properties create mode 100644 src/build.ts delete mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.eslint.json delete mode 100644 tsconfig.esm.json delete mode 100644 tsconfig.types.json diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index e5a2569..0000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,9 +0,0 @@ -const config = require('@chubbyts/chubbyts-eslint/dist/eslintrc').default; - -module.exports = { - ...config, - parserOptions: { - ...config.parserOptions, - project: './tsconfig.json', - }, -}; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c06137b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: CI + +on: + push: + pull_request: + branches: + - master + schedule: + - cron: '0 0 * * *' + +jobs: + node18: + name: Node 18 + runs-on: ubuntu-24.04 + steps: + - name: checkout + uses: actions/checkout@v4 + - name: checkout node + uses: actions/setup-node@v4 + with: + node-version: '18' + - run: npm install + node20: + name: Node 20 + runs-on: ubuntu-24.04 + steps: + - name: checkout + uses: actions/checkout@v4 + - name: checkout node + uses: actions/setup-node@v4 + with: + node-version: '20' + - run: npm install + node22: + name: Node 22 + runs-on: ubuntu-24.04 + steps: + - name: checkout + uses: actions/checkout@v4 + - name: checkout node + uses: actions/setup-node@v4 + with: + node-version: '22' + - run: npm install + - run: npm run lint + - run: npm run cs + - name: sonarcloud.io + uses: sonarsource/sonarqube-scan-action@v4.1.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.gitignore b/.gitignore index d5f19d8..91a3983 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +dist node_modules package-lock.json diff --git a/README.md b/README.md index 01166bc..754ead0 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,14 @@ Packaging helper ## Requirements - * node: 16 + * node: 18 ## Installation Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-packaging][1]. ```ts -npm i -D @chubbyts/chubbyts-packaging@^2.0.6 +npm i -D @chubbyts/chubbyts-packaging@^3.0.0 ``` ### package.json @@ -21,7 +21,7 @@ npm i -D @chubbyts/chubbyts-packaging@^2.0.6 ```json "type": "module", "scripts": { - "build": "node ./build.js", + "build": "node ./build.mjs", ... }, "exports": { @@ -37,15 +37,12 @@ npm i -D @chubbyts/chubbyts-packaging@^2.0.6 ### Symlinks ```sh -ln -sf node_modules/@chubbyts/chubbyts-packaging/build.js . -ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.cjs.json . -ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.esm.json . +ln -sf node_modules/@chubbyts/chubbyts-packaging/dist/build.mjs . ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.json . -ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.types.json . ``` ## Copyright -2024 Dominik Zogg +2025 Dominik Zogg [1]: https://www.npmjs.com/package/@chubbyts/chubbyts-packaging diff --git a/build.js b/build.js deleted file mode 100644 index aae624f..0000000 --- a/build.js +++ /dev/null @@ -1,78 +0,0 @@ -import { execSync } from 'child_process'; -import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'; -import { dirname, basename } from 'path'; - -const getAllFiles = (path) => { - return readdirSync(path) - .map((file) => { - const filePath = path + '/' + file; - if (statSync(filePath).isDirectory()) { - return getAllFiles(filePath); - } - - return [filePath]; - }) - .flat(); -}; - -const distDir = './dist'; -const commonJsDistDir = distDir + '/cjs'; -const ecmaScriptModuleDistDir = distDir + '/esm'; - -rmSync(distDir, { recursive: true, force: true }); - -try { - execSync('./node_modules/.bin/tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json'); - - getAllFiles(commonJsDistDir).map((file) => { - const name = basename(file); - const fromFolder = dirname(file); - const toFolder = distDir + fromFolder.substring(commonJsDistDir.length); - - if (!name.match(/\.js$/)) { - return; - } - - if (!existsSync(toFolder)) { - mkdirSync(toFolder, { recursive: true }); - } - - const fromPath = fromFolder + '/' + name; - const toPath = toFolder + '/' + name.replace(/\.js$/, '.cjs'); - - writeFileSync( - toPath, - readFileSync(fromPath, { encoding: 'utf8', flag: 'r' }).replace(/require\("\.([^"]+)"\)/g, 'require(".$1.cjs")'), - ); - }); - - rmSync(commonJsDistDir, { recursive: true, force: true }); - - getAllFiles(ecmaScriptModuleDistDir).map((file) => { - const name = basename(file); - const fromFolder = dirname(file); - const toFolder = distDir + fromFolder.substring(ecmaScriptModuleDistDir.length); - - if (!name.match(/\.js$/)) { - return; - } - - if (!existsSync(toFolder)) { - mkdirSync(toFolder, { recursive: true }); - } - - const fromPath = fromFolder + '/' + name; - const toPath = toFolder + '/' + name.replace(/\.js$/, '.mjs'); - - writeFileSync( - toPath, - readFileSync(fromPath, { encoding: 'utf8', flag: 'r' }).replace(/from '\.([^']+)'/g, "from '.$1.mjs'"), - ); - }); - - rmSync(ecmaScriptModuleDistDir, { recursive: true, force: true }); -} catch (e) { - console.log(e.stdout.toString()); - console.log(e.stderr.toString()); -} - diff --git a/build.ts b/build.ts new file mode 120000 index 0000000..c5d88f8 --- /dev/null +++ b/build.ts @@ -0,0 +1 @@ +src/build.ts \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..41a3f70 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1 @@ +export { default } from '@chubbyts/chubbyts-eslint/eslint.config'; diff --git a/package.json b/package.json index 228325b..d3de9ce 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@chubbyts/chubbyts-packaging", "type": "module", - "version": "2.0.7", + "version": "3.0.0", "description": "Packaging helper", "keywords": [ "chubbyts", @@ -12,10 +12,12 @@ "license": "MIT", "repository": "chubbyts/chubbyts-packaging", "scripts": { - "cs-fix": "prettier --write build.js", - "cs": "prettier --check build.js", - "lint-fix": "eslint build.js --fix", - "lint": "eslint build.js" + "build": "tsx build.ts", + "cs-fix": "prettier --write src eslint.config.mjs", + "cs": "prettier --check src eslint.config.mjs", + "lint-fix": "eslint src eslint.config.mjs --fix", + "lint": "eslint src", + "prepare": "npm run build" }, "prettier": { "printWidth": 120, @@ -24,18 +26,26 @@ "trailingComma": "all" }, "files": [ - "build.js", - "tsconfig.cjs.json", - "tsconfig.esm.json", - "tsconfig.json", - "tsconfig.types.json" + "dist", + "tsconfig.json" ], + "exports": { + "./*": { + "types": "./*.d.ts", + "require": "./*.cjs", + "import": "./*.mjs", + "default": "./*.mjs" + } + }, "engines": { - "node": ">=16" + "node": ">=18" }, "devDependencies": { - "@chubbyts/chubbyts-eslint": "^2.0.7", - "prettier": "^3.2.5" + "@chubbyts/chubbyts-eslint": "^3.0.0", + "@types/node": "^22.10.5", + "prettier": "^3.4.2", + "tsx": "^4.19.2", + "typescript": "^5.7.2" }, "publishConfig": { "access": "public" diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..3685b9e --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,9 @@ +sonar.organization=chubbyts +sonar.projectKey=chubbyts_chubbyts-packaging +sonar.projectName=chubbyts-packaging + +sonar.sources=src +sonar.tests=tests +sonar.language=typescript +sonar.sourceEncoding=UTF-8 +sonar.javascript.lcov.reportPaths=coverage/lcov.info diff --git a/src/build.ts b/src/build.ts new file mode 100644 index 0000000..468939b --- /dev/null +++ b/src/build.ts @@ -0,0 +1,80 @@ +import { execSync } from 'child_process'; +import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'; +import { dirname, basename } from 'path'; + +const getAllFiles = (path: string): Array => { + return readdirSync(path) + .map((file) => { + const filePath = path + '/' + file; + if (statSync(filePath).isDirectory()) { + return getAllFiles(filePath); + } + + return [filePath]; + }) + .flat(); +}; + +const distDir = './dist'; +const commonJsDistDir = distDir + '/cjs'; +const moduleDistDir = distDir + '/esm'; + +rmSync(distDir, { recursive: true, force: true }); + +try { + execSync(`./node_modules/.bin/tsc --module commonjs --outDir ${commonJsDistDir}`); + execSync(`./node_modules/.bin/tsc --module esnext --outDir ${moduleDistDir}`); + execSync(`./node_modules/.bin/tsc --declaration --emitDeclarationOnly --outDir ${distDir}`); +} catch (e) { + console.log(e?.toString()); + + process.exit(1); +} + +getAllFiles(commonJsDistDir).map((file) => { + const name = basename(file); + const fromFolder = dirname(file); + const toFolder = distDir + fromFolder.substring(commonJsDistDir.length); + + if (!name.match(/\.js$/)) { + return; + } + + if (!existsSync(toFolder)) { + mkdirSync(toFolder, { recursive: true }); + } + + const fromPath = fromFolder + '/' + name; + const toPath = toFolder + '/' + name.replace(/\.js$/, '.cjs'); + + writeFileSync( + toPath, + readFileSync(fromPath, { encoding: 'utf8', flag: 'r' }).replace(/require\("\.([^"]+)"\)/g, 'require(".$1.cjs")'), + ); +}); + +rmSync(commonJsDistDir, { recursive: true, force: true }); + +getAllFiles(moduleDistDir).map((file) => { + const name = basename(file); + const fromFolder = dirname(file); + const toFolder = distDir + fromFolder.substring(moduleDistDir.length); + + if (!name.match(/\.js$/)) { + return; + } + + if (!existsSync(toFolder)) { + mkdirSync(toFolder, { recursive: true }); + } + + const fromPath = fromFolder + '/' + name; + const toPath = toFolder + '/' + name.replace(/\.js$/, '.mjs'); + + writeFileSync( + toPath, + readFileSync(fromPath, { encoding: 'utf8', flag: 'r' }).replace(/from '\.([^']+)'/g, "from '.$1.mjs'"), + ); +}); + +rmSync(moduleDistDir, { recursive: true, force: true }); diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json deleted file mode 100644 index 766983f..0000000 --- a/tsconfig.cjs.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "commonjs", - "outDir": "./dist/cjs" - } -} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..97c9c72 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "eslint.config.mjs", + "src" + ], +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json deleted file mode 100644 index 4cb7d04..0000000 --- a/tsconfig.esm.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "esnext", - "outDir": "./dist/esm" - } -} diff --git a/tsconfig.json b/tsconfig.json index 406779d..dba29fa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { - "jsx": "react", + "esModuleInterop": true, + "module": "ESNext", "moduleResolution": "node", "skipLibCheck": true, "strict": true, diff --git a/tsconfig.types.json b/tsconfig.types.json deleted file mode 100644 index b9d7ed4..0000000 --- a/tsconfig.types.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "outDir": "./dist" - } -}