Skip to content

Commit 19c3315

Browse files
committed
chore: linting
1 parent e985b7f commit 19c3315

File tree

7 files changed

+50
-34
lines changed

7 files changed

+50
-34
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
needs: build
8585
strategy:
8686
matrix:
87-
node-version: [ 12, 14, 16, 18, 20 ]
87+
node-version: [12, 14, 16, 18, 20]
8888
steps:
8989
- uses: actions/checkout@v4
9090
- name: Use Node.js ${{ matrix.node-version }}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"test:smoke:win32": "node ./test/smoke/win32.test.js",
7070
"test:smoke:cjs": "node ./test/smoke/node.test.cjs",
7171
"test:smoke:mjs": "node ./test/smoke/node.test.mjs",
72-
"coverage": "c8 -x build/vendor.js -x 'test/**' -x scripts --check-coverage npm test",
72+
"coverage": "c8 -x build/vendor.cjs -x 'test/**' -x scripts --check-coverage npm test",
7373
"circular": "madge --circular src/*",
7474
"version": "cat package.json | fx .version"
7575
},

scripts/build-js.mjs

+37-22
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,32 @@ const {
5050
cwd: _cwd,
5151
} = argv
5252

53-
const plugins = [transformHookPlugin({
54-
hooks: [{
55-
on: 'end',
56-
pattern: /\.cjs/,
57-
transform(contents) {
58-
return contents
59-
.replaceAll('"node:', '"')
60-
.replaceAll('require("stream/promises")', 'require("stream").promises')
61-
.replaceAll('require("fs/promises")', 'require("fs").promises')
62-
.replaceAll('}).prototype', '}).prototype || {}')
63-
}
64-
}]
65-
})]
53+
const plugins = [
54+
transformHookPlugin({
55+
hooks: [
56+
{
57+
on: 'end',
58+
pattern: /\.cjs/,
59+
transform(contents) {
60+
return contents
61+
.slice(
62+
0,
63+
contents.indexOf(
64+
'// Annotate the CommonJS export names for ESM import in node:'
65+
)
66+
)
67+
.replaceAll('"node:', '"')
68+
.replaceAll(
69+
'require("stream/promises")',
70+
'require("stream").promises'
71+
)
72+
.replaceAll('require("fs/promises")', 'require("fs").promises')
73+
.replaceAll('}).prototype', '}).prototype || {}')
74+
},
75+
},
76+
],
77+
}),
78+
]
6679
const cwd = Array.isArray(_cwd) ? _cwd[_cwd.length - 1] : _cwd
6780
const entries = entry.split(/,\s?/)
6881
const entryPoints = entry.includes('*')
@@ -83,11 +96,13 @@ if (bundle === 'src') {
8396
}
8497

8598
if (hybrid) {
86-
plugins.push(hybridExportPlugin({
87-
loader: 'import',
88-
to: 'build',
89-
toExt: '.js'
90-
}))
99+
plugins.push(
100+
hybridExportPlugin({
101+
loader: 'import',
102+
to: 'build',
103+
toExt: '.js',
104+
})
105+
)
91106
}
92107

93108
const formats = format.split(',')
@@ -115,7 +130,7 @@ const esmConfig = {
115130
target: 'esnext',
116131
format: 'esm',
117132
outExtension: {
118-
'.js': '.mjs'
133+
'.js': '.mjs',
119134
},
120135
plugins,
121136
legalComments: license,
@@ -131,13 +146,13 @@ const cjsConfig = {
131146
format: 'cjs',
132147
banner: {},
133148
outExtension: {
134-
'.js': '.cjs'
149+
'.js': '.cjs',
135150
},
136151
// https://github.com/evanw/esbuild/issues/1633
137152
define: {
138-
'import.meta.url': 'import_meta_url'
153+
'import.meta.url': 'import_meta_url',
139154
},
140-
inject: ['./scripts/import.meta.url-polyfill.js']
155+
inject: ['./scripts/import.meta.url-polyfill.js'],
141156
}
142157

143158
for (const format of formats) {

scripts/import.meta.url-polyfill.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export const import_meta_url =
2-
typeof document === 'undefined' ? new (require('url'.replace('', '')).URL)('file:' + __filename).href :
3-
(document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href)
2+
typeof document === 'undefined'
3+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
4+
: (document.currentScript && document.currentScript.src) ||
5+
new URL('main.js', document.baseURI).href

src/cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ const argv = minimist(process.argv.slice(2), {
5656
boolean: ['version', 'help', 'quiet', 'verbose', 'install', 'repl'],
5757
alias: { e: 'eval', i: 'install', v: 'version', h: 'help' },
5858
stopEarly: true,
59-
});
59+
})
6060

61-
(async function main() {
61+
;(async function main() {
6262
const globals = './globals.js'
6363
await import(globals)
6464
if (argv.verbose) $.verbose = true

src/vendor.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import { AbortController } from 'node-abort-controller'
3232

3333
export { exec, buildCmd } from 'zurk/spawn'
3434

35-
import _createRequire from 'create-require'
35+
import _createRequire from 'create-require'
3636
import { URL } from 'url'
3737

38-
export const createRequire = (_createRequire) as unknown as (filename: string | URL) => NodeRequire
38+
export const createRequire = _createRequire as unknown as (
39+
filename: string | URL
40+
) => NodeRequire
3941

4042
global.AbortController = global.AbortController || AbortController
4143

test/extra.test.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import { globby } from '../build/index.js'
1919

2020
describe('extra', () => {
2121
test('every file should have a license', async () => {
22-
const files = await globby([
23-
'**/*.{js,mjs,ts}',
24-
'!**/*-polyfill.js'
25-
], {
22+
const files = await globby(['**/*.{js,mjs,ts}', '!**/*-polyfill.js'], {
2623
gitignore: true,
2724
onlyFiles: true,
2825
cwd: process.cwd(),

0 commit comments

Comments
 (0)