From e19746b92083c5c6f4c6fb509f02ab2f8cc80674 Mon Sep 17 00:00:00 2001 From: 1aron Date: Tue, 20 Feb 2024 21:27:31 +0800 Subject: [PATCH] Fix: Build source incorrectly referenced the same file address --- packages/techor/src/commands/build.ts | 54 +++++++++---------- packages/techor/tests/bin/package.json | 24 +++++++++ .../tests/{esm-bin => bin}/src/bin/index.ts | 2 - packages/techor/tests/bin/src/index.ts | 1 + packages/techor/tests/bin/test.ts | 15 ++++++ .../tests/{esm-bin => bin}/tsconfig.json | 0 packages/techor/tests/esm-bin/package.json | 12 ----- packages/techor/tests/esm-bin/test.ts | 7 --- packages/techor/tests/pnpm-lock.yaml | 12 ++--- packages/techor/tests/svelte/.gitignore | 3 -- packages/techor/tests/svelte/README.md | 0 packages/techor/tests/svelte/package.json | 30 ----------- .../tests/svelte/src/LazyCSSProvider.svelte | 31 ----------- packages/techor/tests/svelte/src/index.ts | 2 - packages/techor/tests/svelte/src/lazy-css.ts | 9 ---- packages/techor/tests/svelte/techor.ts | 9 ---- packages/techor/tests/svelte/tsconfig.json | 22 -------- 17 files changed, 70 insertions(+), 163 deletions(-) create mode 100644 packages/techor/tests/bin/package.json rename packages/techor/tests/{esm-bin => bin}/src/bin/index.ts (98%) create mode 100644 packages/techor/tests/bin/src/index.ts create mode 100644 packages/techor/tests/bin/test.ts rename packages/techor/tests/{esm-bin => bin}/tsconfig.json (100%) delete mode 100644 packages/techor/tests/esm-bin/package.json delete mode 100644 packages/techor/tests/esm-bin/test.ts delete mode 100644 packages/techor/tests/svelte/.gitignore delete mode 100644 packages/techor/tests/svelte/README.md delete mode 100644 packages/techor/tests/svelte/package.json delete mode 100644 packages/techor/tests/svelte/src/LazyCSSProvider.svelte delete mode 100644 packages/techor/tests/svelte/src/index.ts delete mode 100644 packages/techor/tests/svelte/src/lazy-css.ts delete mode 100644 packages/techor/tests/svelte/techor.ts delete mode 100644 packages/techor/tests/svelte/tsconfig.json diff --git a/packages/techor/src/commands/build.ts b/packages/techor/src/commands/build.ts index 1ba18e0..814ad4b 100644 --- a/packages/techor/src/commands/build.ts +++ b/packages/techor/src/commands/build.ts @@ -49,7 +49,7 @@ const SRCFILE_EXT = '.{js,ts,jsx,cjs,tsx,mjs,mts}' declare type OutputResults = (BuildOutputOptions & { artifact: (RollupOutputAsset | RollupOutputChunk) })[] declare type BuildOutputOptions = BuildCommonOptions & { output: RollupOutputOptions } declare type BuildOptions = { - rollupInput: RollupInputOptions, + input: RollupInputOptions, outputOptionsList: BuildOutputOptions[] } @@ -126,12 +126,12 @@ export default (program: Command) => program.command('build [entryPaths...]') (buildOptions.outputOptionsList).push(outputOptions) } else { buildOptions = { - rollupInput: config.build.input, outputOptionsList: [outputOptions] } as BuildOptions - buildOptions.rollupInput.input = input - buildOptions.rollupInput.external = (config.build.external && !isGlobalFile) && getWideExternal(config.build.external || []); - (buildOptions.rollupInput.plugins as RollupInputPluginOption[]).unshift( + buildOptions.input = extend({}, config.build.input) + buildOptions.input.input = input + buildOptions.input.external = (config.build.external && !isGlobalFile) && getWideExternal(config.build.external || []); + (buildOptions.input.plugins as RollupInputPluginOption[]).unshift( ...[ config.build.swc && swc(config.build.swc), config.build.commonjs && commonjs(config.build.commonjs), @@ -235,7 +235,7 @@ export default (program: Command) => program.command('build [entryPaths...]') return } - log.i`Start watching for file changes...` + if (config.build.watch) log.i`Start watching for file changes...` const outputResults: OutputResults = [] const printOutputResults = (eachOutputResults: OutputResults, eachBuildStartTime: [number, number]) => { const buildTime = process.hrtime(eachBuildStartTime) @@ -283,33 +283,27 @@ export default (program: Command) => program.command('build [entryPaths...]') log.ok(clsx(`Built **${chunks.length}** chunks`, config.build.declare && `and types`, `in ${prettyHartime(buildTime).replace(' ', '')}`)) } const buildStartTime = process.hrtime() - const buildingInputs = [] + const output = async (rollupBuild: RollupBuild, eachOutputOptionsList: BuildOutputOptions[], outputResults: OutputResults) => { + await Promise.all( + eachOutputOptionsList.map(async (eachOutputOptions) => { + const result = await rollupBuild.write(eachOutputOptions.output) + result.output + .forEach((chunkOrAsset) => { + outputResults.push({ + ...eachOutputOptions, + artifact: chunkOrAsset + }) + }) + }) + ) + } await Promise.all( [ ...Array.from(buildMap.entries()) .map(async ([input, eachBuildOptions]) => { - buildingInputs.push(input) - const output = async (rollupBuild: RollupBuild, outputResults: OutputResults) => { - await Promise.all( - eachBuildOptions.outputOptionsList.map(async (eachOutputOptions) => { - const result = await rollupBuild.generate(eachOutputOptions.output) - result.output = result.output - .filter((chunkOrAsset) => { - outputResults.push({ - ...eachOutputOptions, - artifact: chunkOrAsset - }) - return true - }) as RollupOutput['output'] - if (result.output.length) { - await rollupBuild.write(eachOutputOptions.output) - } - }) - ) - } if (config.build.watch) { const watcher = rollupWatch({ - ...eachBuildOptions.rollupInput, + ...eachBuildOptions.input, watch: { skipWrite: true } @@ -322,7 +316,7 @@ export default (program: Command) => program.command('build [entryPaths...]') } if (event.code === 'BUNDLE_END') { const eachOutputResults = [] - await output(event.result, eachOutputResults) + await output(event.result, eachBuildOptions.outputOptionsList, eachOutputResults) printOutputResults(eachOutputResults, buildStartTime) if (config.build.declare) console.log('') } @@ -335,8 +329,8 @@ export default (program: Command) => program.command('build [entryPaths...]') log`[${event.toUpperCase()}] ${relative(process.cwd(), id)}` }) } else { - const rollupBuild = await rollup(eachBuildOptions.rollupInput) - await output(rollupBuild, outputResults) + const rollupBuild = await rollup(eachBuildOptions.input) + await output(rollupBuild, eachBuildOptions.outputOptionsList, outputResults) if (rollupBuild) { // closes the rollupBuild await rollupBuild.close() diff --git a/packages/techor/tests/bin/package.json b/packages/techor/tests/bin/package.json new file mode 100644 index 0000000..6f41968 --- /dev/null +++ b/packages/techor/tests/bin/package.json @@ -0,0 +1,24 @@ +{ + "name": "@test/bin", + "version": "1.0.0", + "private": true, + "bin": "./dist/bin/index.mjs", + "main": "./dist/index.cjs", + "jsnext:main": "./dist/index.mjs", + "esnext": "./dist/index.mjs", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "require": "./dist/index.cjs", + "import": "./dist/index.mjs", + "types": "./dist/index.d.ts" + } + }, + "files": [ + "dist" + ], + "dependencies": { + "ora": "^8.0.1" + } +} \ No newline at end of file diff --git a/packages/techor/tests/esm-bin/src/bin/index.ts b/packages/techor/tests/bin/src/bin/index.ts similarity index 98% rename from packages/techor/tests/esm-bin/src/bin/index.ts rename to packages/techor/tests/bin/src/bin/index.ts index b7b4b38..ef3e44b 100644 --- a/packages/techor/tests/esm-bin/src/bin/index.ts +++ b/packages/techor/tests/bin/src/bin/index.ts @@ -1,7 +1,5 @@ #!/usr/bin/env node - import ora from 'ora' const spinner = ora(`Initializing Master CSS`).start() - console.log(spinner) \ No newline at end of file diff --git a/packages/techor/tests/bin/src/index.ts b/packages/techor/tests/bin/src/index.ts new file mode 100644 index 0000000..2e091bc --- /dev/null +++ b/packages/techor/tests/bin/src/index.ts @@ -0,0 +1 @@ +export const main = 'main' \ No newline at end of file diff --git a/packages/techor/tests/bin/test.ts b/packages/techor/tests/bin/test.ts new file mode 100644 index 0000000..81c6219 --- /dev/null +++ b/packages/techor/tests/bin/test.ts @@ -0,0 +1,15 @@ +import { execSync } from 'node:child_process' +import { expectFileIncludes } from '../../../../utils/expect-file-includes' + +beforeAll(() => { + execSync('tsx ../../src/bin build', { cwd: __dirname }) +}) + +test('bin', () => { + expectFileIncludes('dist/bin/index.mjs', [`#!/usr/bin/env node`], { cwd: __dirname }) +}) + +test('main', () => { + expectFileIncludes('dist/index.mjs', [`export { main };`], { cwd: __dirname }) + expectFileIncludes('dist/index.cjs', [`exports.main = main;`], { cwd: __dirname }) +}) \ No newline at end of file diff --git a/packages/techor/tests/esm-bin/tsconfig.json b/packages/techor/tests/bin/tsconfig.json similarity index 100% rename from packages/techor/tests/esm-bin/tsconfig.json rename to packages/techor/tests/bin/tsconfig.json diff --git a/packages/techor/tests/esm-bin/package.json b/packages/techor/tests/esm-bin/package.json deleted file mode 100644 index 8081eba..0000000 --- a/packages/techor/tests/esm-bin/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "@test/esm-bin", - "version": "1.0.0", - "private": true, - "bin": "./dist/bin/index.mjs", - "files": [ - "dist" - ], - "dependencies": { - "ora": "^8.0.1" - } -} \ No newline at end of file diff --git a/packages/techor/tests/esm-bin/test.ts b/packages/techor/tests/esm-bin/test.ts deleted file mode 100644 index 691be82..0000000 --- a/packages/techor/tests/esm-bin/test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { execSync } from 'node:child_process' -import { expectFileIncludes } from '../../../../utils/expect-file-includes' - -test('esm bin', () => { - execSync('tsx ../../src/bin build', { cwd: __dirname }) - expectFileIncludes('dist/bin/index.mjs', [`import ora from 'ora';`], { cwd: __dirname }) -}) \ No newline at end of file diff --git a/packages/techor/tests/pnpm-lock.yaml b/packages/techor/tests/pnpm-lock.yaml index 9525056..8b1e179 100644 --- a/packages/techor/tests/pnpm-lock.yaml +++ b/packages/techor/tests/pnpm-lock.yaml @@ -20,6 +20,12 @@ importers: b: {} + bin: + dependencies: + ora: + specifier: ^8.0.1 + version: 8.0.1 + c: dependencies: '@test/pack-a': @@ -28,12 +34,6 @@ importers: dev-dependency: {} - esm-bin: - dependencies: - ora: - specifier: ^8.0.1 - version: 8.0.1 - exports: {} external: diff --git a/packages/techor/tests/svelte/.gitignore b/packages/techor/tests/svelte/.gitignore deleted file mode 100644 index c14a095..0000000 --- a/packages/techor/tests/svelte/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -src/**/*.js -src/**/*.map -src/**/*.d.ts \ No newline at end of file diff --git a/packages/techor/tests/svelte/README.md b/packages/techor/tests/svelte/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/packages/techor/tests/svelte/package.json b/packages/techor/tests/svelte/package.json deleted file mode 100644 index fd5296f..0000000 --- a/packages/techor/tests/svelte/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@test/svelte", - "version": "1.0.0", - "private": true, - "type": "module", - "sideEffects": false, - "module": "./dist/index.js", - "types": "./dist/index.d.ts", - "exports": { - ".": { - "import": "./dist/index.js", - "types": "./dist/index.d.ts" - } - }, - "files": [ - "dist" - ], - "publishConfig": { - "access": "public" - }, - "peerDependencies": { - "svelte": ">= 3.0.0" - }, - "dependencies": { - "@master/css": "^2.0.0-beta.130" - }, - "devDependencies": { - "@tsconfig/svelte": "^3.0.0" - } -} \ No newline at end of file diff --git a/packages/techor/tests/svelte/src/LazyCSSProvider.svelte b/packages/techor/tests/svelte/src/LazyCSSProvider.svelte deleted file mode 100644 index 8f8c5f1..0000000 --- a/packages/techor/tests/svelte/src/LazyCSSProvider.svelte +++ /dev/null @@ -1,31 +0,0 @@ - - - diff --git a/packages/techor/tests/svelte/src/index.ts b/packages/techor/tests/svelte/src/index.ts deleted file mode 100644 index 36355b4..0000000 --- a/packages/techor/tests/svelte/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './lazy-css' -export { default as LazyCSSProvider } from './LazyCSSProvider.svelte' \ No newline at end of file diff --git a/packages/techor/tests/svelte/src/lazy-css.ts b/packages/techor/tests/svelte/src/lazy-css.ts deleted file mode 100644 index 9762241..0000000 --- a/packages/techor/tests/svelte/src/lazy-css.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { MasterCSS } from '@master/css' -import { getContext } from 'svelte' -import type { Writable } from 'svelte/store' - -export const lazyCSSSymbol = Symbol() - -export function getLazyCSS() { - return getContext | undefined>(lazyCSSSymbol) -} \ No newline at end of file diff --git a/packages/techor/tests/svelte/techor.ts b/packages/techor/tests/svelte/techor.ts deleted file mode 100644 index f272180..0000000 --- a/packages/techor/tests/svelte/techor.ts +++ /dev/null @@ -1,9 +0,0 @@ - -/** @type {import('techor').Config} */ -export default { - pack: { - plugins: [ - - ] - } -} \ No newline at end of file diff --git a/packages/techor/tests/svelte/tsconfig.json b/packages/techor/tests/svelte/tsconfig.json deleted file mode 100644 index a9a57af..0000000 --- a/packages/techor/tests/svelte/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "extends": "@tsconfig/svelte/tsconfig.json", - "compilerOptions": { - "baseUrl": ".", - "ignoreDeprecations": "5.0", - "outDir": "src", - "declaration": true, - "paths": { - "*.ts": [ - "*.svelte" - ] - }, - }, - "include": [ - "src/**/*" - ], - "exclude": [ - "node_modules/*", - "__sapper__/*", - "public/*" - ], -} \ No newline at end of file