From 731c381703222bba417b4b6686fced4e2bf63fbf Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Sun, 17 Dec 2023 19:20:50 +0100 Subject: [PATCH 1/3] refactor: simplify redudant calls, polish code --- src/build-config.ts | 9 +++------ src/plugins/prepend-directives.ts | 1 - src/plugins/raw-plugin.ts | 9 ++++----- test/post-build/integration.test.ts | 3 ++- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/build-config.ts b/src/build-config.ts index 74ee0dc8..2a523061 100644 --- a/src/build-config.ts +++ b/src/build-config.ts @@ -49,8 +49,6 @@ const swcMinifyOptions = { compress: true, format: { comments: 'some', - // wrapFuncArgs: false, - // preserveAnnotations: true, }, mangle: { toplevel: true, @@ -309,13 +307,12 @@ function buildOutputConfigs( '.d.ts', ) - // If there's dts file, use `output.file` - const dtsPathConfig = dtsFile ? { dir: dirname(dtsFile) } : { dir: dtsDir } + const dtsPathConfig = { dir: dtsFile ? dirname(dtsFile) : dtsDir } const outputFile: string = (dtsFile || file)! return { name: pkg.name || name, - ...(dts ? dtsPathConfig : { dir: dirname(outputFile!) }), + ...(dts ? dtsPathConfig : { dir: dirname(outputFile) }), format, exports: 'named', esModule: useEsModuleMark || 'if-default-prop', @@ -325,7 +322,7 @@ function buildOutputConfigs( sourcemap: options.sourcemap, manualChunks: splitChunks, chunkFileNames: '[name].js', - entryFileNames: basename(outputFile!), + entryFileNames: basename(outputFile), } } diff --git a/src/plugins/prepend-directives.ts b/src/plugins/prepend-directives.ts index de004f87..1c7d0122 100644 --- a/src/plugins/prepend-directives.ts +++ b/src/plugins/prepend-directives.ts @@ -9,7 +9,6 @@ export function prependDirectives(): Plugin { const moduleInfo = this.getModuleInfo(id) if (moduleInfo?.meta?.preserveDirectives) { const firstDirective = moduleInfo.meta.preserveDirectives.directives[0] - console.log('prepend', id, firstDirective) if (firstDirective) { const directive = firstDirective.value const directiveCode = `'${directive}';` diff --git a/src/plugins/raw-plugin.ts b/src/plugins/raw-plugin.ts index 38f5bc68..b9472ce9 100644 --- a/src/plugins/raw-plugin.ts +++ b/src/plugins/raw-plugin.ts @@ -2,20 +2,19 @@ import { type FilterPattern, createFilter } from '@rollup/pluginutils' import type { Plugin } from 'rollup' export function rawContent({ exclude }: { exclude: FilterPattern }): Plugin { - /\.(data|txt)$/ const filter = createFilter(['**/*.data', '**/*.txt'], exclude) return { - name: "string", + name: 'string', transform(code, id) { if (filter(id)) { return { - code: `export default ${JSON.stringify(code)}`, - map: undefined, + code: `const data = ${JSON.stringify(code)};\nexport default data;`, + map: null, } } - return undefined + return null } } } diff --git a/test/post-build/integration.test.ts b/test/post-build/integration.test.ts index 185cfb0d..0f3ebbfe 100644 --- a/test/post-build/integration.test.ts +++ b/test/post-build/integration.test.ts @@ -1,2 +1,3 @@ -import '../integration.test' process.env.POST_BUILD = '1' + +import('../integration.test') From 147d5d3bf4d72d90b0cbe0944439fbb0b577c78b Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Sun, 17 Dec 2023 19:27:41 +0100 Subject: [PATCH 2/3] simplify post build test --- .github/workflows/ci.yml | 4 +++- package.json | 1 + test/post-build/compile.test.ts | 2 -- test/post-build/integration.test.ts | 3 --- 4 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 test/post-build/compile.test.ts delete mode 100644 test/post-build/integration.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13f21aa4..8fecbc13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,9 @@ jobs: run: pnpm build - name: Test - run: pnpm test + run: | + pnpm test + pnpm test:post release: runs-on: ubuntu-latest diff --git a/package.json b/package.json index 5d8e3c54..ed65c40b 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "test": "jest --env node", "test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test", + "test:post": "POST_BUILD=1 pnpm test test/compile.test.ts test/integration.test.ts", "clean": "rm -rf ./dist", "typecheck": "tsc --noEmit", "prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/bin/cli.js && pnpm test", diff --git a/test/post-build/compile.test.ts b/test/post-build/compile.test.ts deleted file mode 100644 index 71d01a29..00000000 --- a/test/post-build/compile.test.ts +++ /dev/null @@ -1,2 +0,0 @@ -import '../compile.test' -process.env.POST_BUILD = '1' diff --git a/test/post-build/integration.test.ts b/test/post-build/integration.test.ts deleted file mode 100644 index 0f3ebbfe..00000000 --- a/test/post-build/integration.test.ts +++ /dev/null @@ -1,3 +0,0 @@ -process.env.POST_BUILD = '1' - -import('../integration.test') From 03bccadf0ad4be0bd2e8cc650d050e3297b54ad7 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Sun, 17 Dec 2023 19:38:16 +0100 Subject: [PATCH 3/3] fix compile post build test --- package.json | 2 +- test/compile.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ed65c40b..941a3417 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "test": "jest --env node", "test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test", - "test:post": "POST_BUILD=1 pnpm test test/compile.test.ts test/integration.test.ts", + "test:post": "POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts", "clean": "rm -rf ./dist", "typecheck": "tsc --noEmit", "prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/bin/cli.js && pnpm test", diff --git a/test/compile.test.ts b/test/compile.test.ts index 4d025f78..889b563e 100644 --- a/test/compile.test.ts +++ b/test/compile.test.ts @@ -2,8 +2,8 @@ import fs, { promises as fsp } from 'fs' import { resolve, dirname, extname } from 'path' import { existsFile, fullExtension } from './testing-utils' -const assetPath = process.env.POST_BUILD ? '../dist' : '../src/bundle' -const bundle = require(assetPath).default +const assetPath = process.env.POST_BUILD ? '..' : '../src/index.ts' +const bundle = require(assetPath).bundle jest.setTimeout(10 * 60 * 1000)