diff --git a/.eslintignore b/.eslintignore index 32e68a98cdc..6e9d3966136 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ test/*/samples/**/*.js !test/*/samples/**/_config.js test/leak/index.js +**/*.ts \ No newline at end of file diff --git a/cli/run/build.ts b/cli/run/build.ts index cc8b01d9985..ec2e5abe104 100644 --- a/cli/run/build.ts +++ b/cli/run/build.ts @@ -1,7 +1,7 @@ import ms from 'pretty-ms'; import tc from 'turbocolor'; import * as rollup from '../../src/node-entry'; -import { InputOptions, OutputAsset, OutputChunk, OutputOptions, RollupBuild, SourceMap } from '../../src/rollup/types'; +import { InputOptions, OutputOptions, RollupBuild, SourceMap } from '../../src/rollup/types'; import relativeId from '../../src/utils/relativeId'; import { handleError, stderr } from '../logging'; import SOURCEMAPPING_URL from '../sourceMappingUrl'; @@ -49,12 +49,12 @@ export default function build( return bundle.generate(output).then(({ output: outputs }) => { for (const file of outputs) { let source: string | Buffer; - if ((file as OutputAsset).isAsset) { - source = (file as OutputAsset).source; + if (file.type === 'asset') { + source = file.source; } else { - source = (file as OutputChunk).code; + source = file.code; if (output.sourcemap === 'inline') { - source += `\n//# ${SOURCEMAPPING_URL}=${((file as OutputChunk) + source += `\n//# ${SOURCEMAPPING_URL}=${(file .map as SourceMap).toUrl()}\n`; } } diff --git a/docs/02-javascript-api.md b/docs/02-javascript-api.md index 634638372f9..06471e94a99 100755 --- a/docs/02-javascript-api.md +++ b/docs/02-javascript-api.md @@ -25,12 +25,13 @@ async function build() { const { output } = await bundle.generate(outputOptions); for (const chunkOrAsset of output) { - if (chunkOrAsset.isAsset) { + if (chunkOrAsset.type === 'asset') { // For assets, this contains // { - // isAsset: true, // signifies that this is an asset + // isAsset: true, // signifies that this is an asset, !deprecated use type === asset instead // fileName: string, // the asset file name // source: string | Buffer // the asset source + // type: 'asset' // } console.log('Asset', chunkOrAsset); } else { @@ -54,6 +55,7 @@ async function build() { // }; // }, // name: string // the name of this chunk as used in naming patterns + // type: 'chunk', // } console.log('Chunk', chunkOrAsset.modules); } diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index e42309a8ad3..5f2f4177d22 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -123,8 +123,9 @@ Called at the end of `bundle.generate()` or immediately before the files are wri // AssetInfo { fileName: string, - isAsset: true, - source: string | Buffer + isAsset: true, // deprecated + source: string | Buffer, + type: 'asset', } // ChunkInfo @@ -146,7 +147,8 @@ Called at the end of `bundle.generate()` or immediately before the files are wri originalLength: number }, }, - name: string + name: string, + type: 'chunk', } ``` diff --git a/package-lock.json b/package-lock.json index 2d4ed90320b..ea09d24fd56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1614,9 +1614,9 @@ } }, "eslint-utils": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.0.tgz", - "integrity": "sha512-7ehnzPaP5IIEh1r1tkjuIrxqhNkzUJa9z3R92tLJdZIVdWaczEhr3EbhGtsMrVxi1KeR8qA7Off6SWc5WNQqyQ==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz", + "integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==", "dev": true, "requires": { "eslint-visitor-keys": "^1.0.0" diff --git a/src/rollup/index.ts b/src/rollup/index.ts index 4f0246b0f54..10e04a91ee1 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -166,6 +166,7 @@ function assignChunksToBundle( isEntry: facadeModule !== null && facadeModule.isEntryPoint, map: undefined, modules: chunk.renderedModules, + type: 'chunk', get name() { return chunk.getChunkName(); } @@ -301,7 +302,7 @@ export default async function rollup(rawInputOptions: GenericConfigObject): Prom let chunkCnt = 0; for (const fileName of Object.keys(bundle)) { const file = bundle[fileName]; - if ((file as OutputAsset).isAsset) continue; + if (file.type === 'asset') continue; chunkCnt++; if (chunkCnt > 1) break; } @@ -343,10 +344,10 @@ enum SortingFileType { } function getSortingFileType(file: OutputAsset | OutputChunk): SortingFileType { - if ((file as OutputAsset).isAsset) { + if (file.type === 'asset') { return SortingFileType.ASSET; } - if ((file as OutputChunk).isEntry) { + if (file.isEntry) { return SortingFileType.ENTRY_CHUNK; } return SortingFileType.SECONDARY_CHUNK; @@ -368,7 +369,7 @@ function createOutput(outputBundle: Record