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

refactor: simplify redudant calls, polish code #306

Merged
merged 3 commits into from
Dec 17, 2023
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
run: pnpm build

- name: Test
run: pnpm test
run: |
pnpm test
pnpm test:post

release:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 3 additions & 6 deletions src/build-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const swcMinifyOptions = {
compress: true,
format: {
comments: 'some',
// wrapFuncArgs: false,
// preserveAnnotations: true,
},
mangle: {
toplevel: true,
Expand Down Expand Up @@ -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',
Expand All @@ -325,7 +322,7 @@ function buildOutputConfigs(
sourcemap: options.sourcemap,
manualChunks: splitChunks,
chunkFileNames: '[name].js',
entryFileNames: basename(outputFile!),
entryFileNames: basename(outputFile),
}
}

Expand Down
1 change: 0 additions & 1 deletion src/plugins/prepend-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}';`
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/raw-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions test/post-build/compile.test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions test/post-build/integration.test.ts

This file was deleted.