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..941a3417 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 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/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/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) 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 185cfb0d..00000000 --- a/test/post-build/integration.test.ts +++ /dev/null @@ -1,2 +0,0 @@ -import '../integration.test' -process.env.POST_BUILD = '1'