Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: up deps #2

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: ${{ github.ref == 'refs/heads/master' && '0' || '1' }}

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
# cache: 'yarn'
Expand Down Expand Up @@ -66,10 +66,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
# cache: 'yarn'
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
],
"scripts": {
"build": "concurrently 'npm:build:*'",
"build:esm": "node ./src/scripts/build.cjs",
"build:cjs": "node ./src/scripts/build.cjs --cjs",
"build:js": "node ./src/scripts/build.mjs",
"build:dts": "tsc --emitDeclarationOnly --skipLibCheck --outDir target/dts",
"build:docs": "typedoc --options src/main/typedoc",
"build:stamp": "npm_config_yes=true npx buildstamp",
"build:stamp": "npx buildstamp",
"test": "concurrently 'npm:test:*'",
"test:lint": "eslint -c src/test/lint/.eslintrc.json src",
"test:unit": "c8 -r lcov -r text -o target/coverage -x src/scripts -x src/test node --loader ts-node/esm --experimental-specifier-resolution=node src/scripts/test.mjs"
Expand All @@ -42,16 +41,18 @@
"homepage": "https://github.com/antongolub/blank-ts#readme",
"dependencies": {},
"devDependencies": {
"@types/node": "^20.10.6",
"c8": "^9.0.0",
"@types/node": "^20.11.15",
"c8": "^9.1.0",
"concurrently": "^8.2.2",
"esbuild": "^0.19.11",
"esbuild": "^0.20.0",
"esbuild-node-externals": "^1.12.0",
"esbuild-plugin-entry-chunks": "^0.1.5",
"eslint": "^8.56.0",
"eslint-config-qiwi": "^2.1.3",
"fast-glob": "^3.3.2",
"minimist": "^1.2.8",
"ts-node": "^10.9.2",
"typedoc": "^0.25.6",
"typedoc": "^0.25.7",
"typescript": "^5.3.3"
}
}
40 changes: 0 additions & 40 deletions src/scripts/build.cjs

This file was deleted.

99 changes: 99 additions & 0 deletions src/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env node

import esbuild from 'esbuild'
import { nodeExternalsPlugin } from 'esbuild-node-externals'
import { entryChunksPlugin } from 'esbuild-plugin-entry-chunks'
import minimist from 'minimist'
import glob from 'fast-glob'

const argv = minimist(process.argv.slice(2), {
default: {
entry: './src/main/ts/index.ts',
external: 'node:*',
bundle: 'src', // 'all' | 'none'
license: 'eof',
minify: false,
sourcemap: false,
format: 'cjs,esm',
cwd: process.cwd()
},
boolean: ['minify', 'sourcemap', 'banner'],
string: ['entry', 'external', 'bundle', 'license', 'format', 'map', 'cwd']
})
const { entry, external, bundle, minify, sourcemap, license, format, cwd: _cwd } = argv

const plugins = []
const cwd = Array.isArray(_cwd) ? _cwd[_cwd.length - 1] : _cwd
const entryPoints = entry.includes('*')
? await glob(entry.split(':'), { absolute: false, onlyFiles: true, cwd })
: entry.split(':')

const _bundle = bundle !== 'none' && !process.argv.includes('--no-bundle')
const _external = _bundle
? external.split(',')
: undefined // https://github.com/evanw/esbuild/issues/1466

if (_bundle && entryPoints.length > 1) {
plugins.push(entryChunksPlugin())
}

if (bundle === 'src') {
// https://github.com/evanw/esbuild/issues/619
// https://github.com/pradel/esbuild-node-externals/pull/52
plugins.push(nodeExternalsPlugin())
}

const formats = format.split(',')
const banner = argv.banner && bundle === 'all'
? {
js: `
const require = (await import("node:module")).createRequire(import.meta.url);
const __filename = (await import("node:url")).fileURLToPath(import.meta.url);
const __dirname = (await import("node:path")).dirname(__filename);
`
}
: {}


const esmConfig = {
absWorkingDir: cwd,
entryPoints,
outdir: './target/esm',
bundle: _bundle,
external: _external,
minify,
sourcemap,
sourcesContent: false,
platform: 'node',
target: 'esnext',
format: 'esm',
outExtension: {
'.js': '.mjs'
},
plugins,
legalComments: license,
tsconfig: './tsconfig.json',
//https://github.com/evanw/esbuild/issues/1921
banner
}

const cjsConfig = {
...esmConfig,
outdir: './target/cjs',
target: 'es6',
format: 'cjs',
banner: {},
outExtension: {
'.js': '.cjs'
}
}

for (const format of formats) {
const config = format === 'cjs' ? cjsConfig : esmConfig

await esbuild
.build(config)
.catch(() => process.exit(1))
}

process.exit(0)
Loading