fix: node 12.20.0 compatibility

This commit is contained in:
EGOIST 2022-01-29 18:06:20 +08:00
parent b26ea64fe8
commit b8c51f4553
7 changed files with 82 additions and 47 deletions

View File

@ -33,7 +33,7 @@
]
},
"dependencies": {
"bundle-require": "^2.1.8",
"bundle-require": "^3.0.2",
"cac": "^6.7.12",
"chokidar": "^3.5.1",
"debug": "^4.3.1",
@ -68,6 +68,7 @@
"rollup-plugin-dts": "4.1.0",
"rollup-plugin-hashbang": "2.2.2",
"string-argv": "0.3.1",
"strip-json-comments": "^4.0.0",
"svelte": "3.44.3",
"ts-essentials": "9.1.2",
"tsconfig-paths": "3.12.0",

27
pnpm-lock.yaml generated
View File

@ -9,7 +9,7 @@ specifiers:
'@types/node': 14.18.4
'@types/resolve': 1.20.1
ava: 4.0.0
bundle-require: ^2.1.8
bundle-require: ^3.0.2
cac: ^6.7.12
chokidar: ^3.5.1
colorette: 2.0.16
@ -32,6 +32,7 @@ specifiers:
rollup-plugin-hashbang: 2.2.2
source-map: ^0.7.3
string-argv: 0.3.1
strip-json-comments: ^4.0.0
sucrase: ^3.20.3
svelte: 3.44.3
tree-kill: ^1.2.2
@ -42,7 +43,7 @@ specifiers:
wait-for-expect: 3.0.2
dependencies:
bundle-require: 2.1.8_esbuild@0.14.2
bundle-require: 3.0.2_esbuild@0.14.2
cac: 6.7.12
chokidar: 3.5.2
debug: 4.3.2
@ -77,6 +78,7 @@ devDependencies:
rollup-plugin-dts: 4.1.0_rollup@2.60.1+typescript@4.5.4
rollup-plugin-hashbang: 2.2.2
string-argv: 0.3.1
strip-json-comments: 4.0.0
svelte: 3.44.3
ts-essentials: 9.1.2_typescript@4.5.4
tsconfig-paths: 3.12.0
@ -524,6 +526,17 @@ packages:
esbuild: '>=0.13'
dependencies:
esbuild: 0.14.2
dev: true
/bundle-require/3.0.2_esbuild@0.14.2:
resolution: {integrity: sha512-WLS50LRdi8oAMnQfoxqjI3Fszi0xaI6dJumvtX909u0WREkYCuFGeE2UwMn5H8bSUXWtUB0XeBqNkgpVjMcYyQ==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
peerDependencies:
esbuild: '>=0.13'
dependencies:
esbuild: 0.14.2
load-tsconfig: 0.2.2
dev: false
/cac/6.7.12:
resolution: {integrity: sha512-rM7E2ygtMkJqD9c7WnFU6fruFcN3xe4FM5yUmgxhZzIKJk4uHl9U/fhwdajGFQbQuv43FAUo1Fe8gX/oIKDeSA==}
@ -1276,6 +1289,11 @@ packages:
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: true
/load-tsconfig/0.2.2:
resolution: {integrity: sha512-9B4XOMjNhphRmXg3YHFnpgEH5fmYKofXJ7M6sLkRcfJ5DcuPiStlQ1Or+1Rv/aML716kQ9Q+C9zJGUcfMYiq4Q==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: false
/locate-path/7.0.0:
resolution: {integrity: sha512-+cg2yXqDUKfo4hsFxwa3G1cBJeA+gs1vD8FyV9/odWoUlQe/4syxHQ5DPtKjtfm6gnKbZzjCqzX03kXosvZB1w==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@ -1756,6 +1774,11 @@ packages:
resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==}
engines: {node: '>=6'}
/strip-json-comments/4.0.0:
resolution: {integrity: sha512-LzWcbfMbAsEDTRmhjWIioe8GcDRl0fa35YMXFoJKDdiD/quGFmjJjdgPjFJJNwCMaLyQqFIDqCdHD2V4HfLgYA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: true
/sucrase/3.20.3:
resolution: {integrity: sha512-azqwq0/Bs6RzLAdb4dXxsCgMtAaD2hzmUr4UhSfsxO46JFPAwMnnb441B/qsudZiS6Ylea3JXZe3Q497lsgXzQ==}
engines: {node: '>=8'}

View File

@ -7,7 +7,6 @@ import { loadTsupConfig } from './load'
import glob from 'globby'
import { loadTsConfig } from 'bundle-require'
import { handleError, PrettyError } from './errors'
import resolveFrom from 'resolve-from'
import { parseArgsStringToArgv } from 'string-argv'
import type { ChildProcess } from 'child_process'
import execa from 'execa'
@ -105,7 +104,7 @@ const normalizeOptions = async (
}
const tsconfig = loadTsConfig(process.cwd(), options.tsconfig)
if (tsconfig.path) {
if (tsconfig) {
logger.info(
'CLI',
`Using tsconfig: ${path.relative(process.cwd(), tsconfig.path)}`

View File

@ -1,8 +1,9 @@
import fs from 'fs'
import JoyCon from 'joycon'
import path from 'path'
import { bundleRequire, jsoncParse } from 'bundle-require'
import { bundleRequire } from 'bundle-require'
import { defineConfig } from './'
import { jsoncParse } from './utils'
const joycon = new JoyCon()

View File

@ -1,6 +1,7 @@
import fs from 'fs'
import glob from 'globby'
import resolveFrom from 'resolve-from'
import strip from 'strip-json-comments'
export type External =
| string
@ -116,3 +117,13 @@ type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T // from
export function truthy<T>(value: T): value is Truthy<T> {
return Boolean(value)
}
export function jsoncParse(data: string) {
try {
return new Function('return ' + strip(data).trim())()
} catch {
// Silently ignore any error
// That's what tsc/jsonc-parser did after all
return {}
}
}

View File

@ -3,8 +3,8 @@ import { join, resolve } from 'path'
import execa from 'execa'
import fs from 'fs-extra'
import glob from 'globby'
import waitForExpect from 'wait-for-expect'
import { debouncePromise } from '../src/utils'
// import waitForExpect from 'wait-for-expect'
// import { debouncePromise } from '../src/utils'
const cacheDir = resolve(__dirname, '.cache')
const bin = resolve(__dirname, '../dist/cli-default.js')
@ -522,52 +522,52 @@ test(`transform __dirname, __filename in esm format`, async (t) => {
t.snapshot(await getFileContent('dist/input.mjs'))
})
test('debounce promise', async (t) => {
try {
const equal = <T>(a: T, b: T) => {
const result = a === b
if (!result) throw new Error(`${a} !== ${b}`)
}
// test('debounce promise', async (t) => {
// try {
// const equal = <T>(a: T, b: T) => {
// const result = a === b
// if (!result) throw new Error(`${a} !== ${b}`)
// }
const sleep = (n: number = ~~(Math.random() * 50) + 20) =>
new Promise<void>((resolve) => setTimeout(resolve, n))
// const sleep = (n: number = ~~(Math.random() * 50) + 20) =>
// new Promise<void>((resolve) => setTimeout(resolve, n))
let n = 0
// let n = 0
const debounceFunction = debouncePromise(
async () => {
await sleep()
++n
},
100,
(err: any) => {
t.fail(err)
}
)
// const debounceFunction = debouncePromise(
// async () => {
// await sleep()
// ++n
// },
// 100,
// (err: any) => {
// t.fail(err)
// }
// )
t.deepEqual(n, 0)
// t.deepEqual(n, 0)
debounceFunction()
debounceFunction()
debounceFunction()
debounceFunction()
// debounceFunction()
// debounceFunction()
// debounceFunction()
// debounceFunction()
await waitForExpect(() => {
equal(n, 1)
})
await sleep(100)
// await waitForExpect(() => {
// equal(n, 1)
// })
// await sleep(100)
t.deepEqual(n, 1)
// t.deepEqual(n, 1)
debounceFunction()
// debounceFunction()
await waitForExpect(() => {
equal(n, 2)
})
} catch (err: any) {
return t.fail(err)
}
})
// await waitForExpect(() => {
// equal(n, 2)
// })
// } catch (err: any) {
// return t.fail(err)
// }
// })
test('exclude dependencies', async (t) => {
const { getFileContent } = await run(t.title, {
@ -767,7 +767,7 @@ test('multiple targets', async (t) => {
{
'input.ts': `
export const answer = 42
`
`,
},
{
entry: ['input.ts'],

View File

@ -1,8 +1,8 @@
import fs from 'fs'
import { defineConfig } from 'tsup'
export default defineConfig({
name: 'tsup',
target: 'node12.20.0',
dts: {
resolve: true,
// build types for `src/index.ts` only