diff --git a/CHANGELOG.md b/CHANGELOG.md index 8994b2f26..c09fa6b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # rollup changelog +## 4.23.0 + +_2024-10-01_ + +### Features + +- Collect all emitted names and originalFileNames for assets (#5686) + +### Pull Requests + +- [#5686](https://github.com/rollup/rollup/pull/5686): Add names and originalFileNames to assets (@lukastaegert) + ## 4.22.5 _2024-09-27_ diff --git a/browser/package.json b/browser/package.json index 1295c54a0..4c6d456d7 100644 --- a/browser/package.json +++ b/browser/package.json @@ -1,6 +1,6 @@ { "name": "@rollup/browser", - "version": "4.22.5", + "version": "4.23.0", "description": "Next-generation ES module bundler browser build", "main": "dist/rollup.browser.js", "module": "dist/es/rollup.browser.js", diff --git a/docs/configuration-options/index.md b/docs/configuration-options/index.md index a70863477..902167281 100755 --- a/docs/configuration-options/index.md +++ b/docs/configuration-options/index.md @@ -574,8 +574,8 @@ export default { ```typescript interface PreRenderedAsset { - name: string | undefined; - originalFileName: string | null; + names: string[]; + originalFileNames: string[]; source: string | Uint8Array; type: 'asset'; } diff --git a/docs/plugin-development/index.md b/docs/plugin-development/index.md index 213eefaa6..d02cdb03f 100644 --- a/docs/plugin-development/index.md +++ b/docs/plugin-development/index.md @@ -908,9 +908,9 @@ function augmentWithDatePlugin() { ```typescript interface OutputAsset { fileName: string; - name: string | undefined; + names: string[]; needsCodeReference: boolean; - originalFileName: string | null; + originalFileNames: string[]; source: string | Uint8Array; type: 'asset'; } diff --git a/package-lock.json b/package-lock.json index a33fb10b5..7ce0abdcf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rollup", - "version": "4.22.5", + "version": "4.23.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rollup", - "version": "4.22.5", + "version": "4.23.0", "license": "MIT", "dependencies": { "@types/estree": "1.0.6" @@ -40,6 +40,7 @@ "@types/node": "^18.19.50", "@types/semver": "^7.5.8", "@types/yargs-parser": "^21.0.3", + "@vue/language-server": "^2.1.6", "acorn": "^8.12.1", "acorn-import-assertions": "^1.9.0", "buble": "^0.20.0", @@ -1041,6 +1042,61 @@ } } }, + "node_modules/@emmetio/abbreviation": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@emmetio/abbreviation/-/abbreviation-2.3.3.tgz", + "integrity": "sha512-mgv58UrU3rh4YgbE/TzgLQwJ3pFsHHhCLqY20aJq+9comytTXUDNGG/SMtSeMJdkpxgXSXunBGLD8Boka3JyVA==", + "dev": true, + "dependencies": { + "@emmetio/scanner": "^1.0.4" + } + }, + "node_modules/@emmetio/css-abbreviation": { + "version": "2.1.8", + "resolved": "https://registry.npmjs.org/@emmetio/css-abbreviation/-/css-abbreviation-2.1.8.tgz", + "integrity": "sha512-s9yjhJ6saOO/uk1V74eifykk2CBYi01STTK3WlXWGOepyKa23ymJ053+DNQjpFcy1ingpaO7AxCcwLvHFY9tuw==", + "dev": true, + "dependencies": { + "@emmetio/scanner": "^1.0.4" + } + }, + "node_modules/@emmetio/css-parser": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@emmetio/css-parser/-/css-parser-0.4.0.tgz", + "integrity": "sha512-z7wkxRSZgrQHXVzObGkXG+Vmj3uRlpM11oCZ9pbaz0nFejvCDmAiNDpY75+wgXOcffKpj4rzGtwGaZxfJKsJxw==", + "dev": true, + "dependencies": { + "@emmetio/stream-reader": "^2.2.0", + "@emmetio/stream-reader-utils": "^0.1.0" + } + }, + "node_modules/@emmetio/html-matcher": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@emmetio/html-matcher/-/html-matcher-1.3.0.tgz", + "integrity": "sha512-NTbsvppE5eVyBMuyGfVu2CRrLvo7J4YHb6t9sBFLyY03WYhXET37qA4zOYUjBWFCRHO7pS1B9khERtY0f5JXPQ==", + "dev": true, + "dependencies": { + "@emmetio/scanner": "^1.0.0" + } + }, + "node_modules/@emmetio/scanner": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@emmetio/scanner/-/scanner-1.0.4.tgz", + "integrity": "sha512-IqRuJtQff7YHHBk4G8YZ45uB9BaAGcwQeVzgj/zj8/UdOhtQpEIupUhSk8dys6spFIWVZVeK20CzGEnqR5SbqA==", + "dev": true + }, + "node_modules/@emmetio/stream-reader": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@emmetio/stream-reader/-/stream-reader-2.2.0.tgz", + "integrity": "sha512-fXVXEyFA5Yv3M3n8sUGT7+fvecGrZP4k6FnWWMSZVQf69kAq0LLpaBQLGcPR30m3zMmKYhECP4k/ZkzvhEW5kw==", + "dev": true + }, + "node_modules/@emmetio/stream-reader-utils": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@emmetio/stream-reader-utils/-/stream-reader-utils-0.1.0.tgz", + "integrity": "sha512-ZsZ2I9Vzso3Ho/pjZFsmmZ++FWeEd/txqybHTm4OgaZzdS8V9V/YYWQwg5TC38Z7uLWUV1vavpLLbjJtKubR1A==", + "dev": true + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -2006,6 +2062,12 @@ "node": ">=8" } }, + "node_modules/@johnsoncodehk/pug-beautify": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@johnsoncodehk/pug-beautify/-/pug-beautify-0.2.2.tgz", + "integrity": "sha512-qqNS/YD0Nck5wtQLCPHAfGVgWbbGafxSPjNh0ekYPFSNNqnDH2kamnduzYly8IiADmeVx/MfAE1njMEjVeHTMA==", + "dev": true + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", @@ -3339,6 +3401,35 @@ "@volar/source-map": "2.4.5" } }, + "node_modules/@volar/language-server": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/@volar/language-server/-/language-server-2.4.5.tgz", + "integrity": "sha512-l5PswE0JzCtstTlwBUpikeSa3lNUBJhTuWtj9KclZTGi2Uex4RcqGOhTiDsUUtvdv/hEuYCxGq1EdJJPlQsD/g==", + "dev": true, + "dependencies": { + "@volar/language-core": "2.4.5", + "@volar/language-service": "2.4.5", + "@volar/typescript": "2.4.5", + "path-browserify": "^1.0.1", + "request-light": "^0.7.0", + "vscode-languageserver": "^9.0.1", + "vscode-languageserver-protocol": "^3.17.5", + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-uri": "^3.0.8" + } + }, + "node_modules/@volar/language-service": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/@volar/language-service/-/language-service-2.4.5.tgz", + "integrity": "sha512-xiFlL0aViGg6JhwAXyohPrdlID13uom8WQg6DWYaV8ob8RRy+zoLlBUI8SpQctwlWEO9poyrYK01revijAwkcw==", + "dev": true, + "dependencies": { + "@volar/language-core": "2.4.5", + "vscode-languageserver-protocol": "^3.17.5", + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-uri": "^3.0.8" + } + }, "node_modules/@volar/source-map": { "version": "2.4.5", "resolved": "https://registry.npmjs.org/@volar/source-map/-/source-map-2.4.5.tgz", @@ -3346,6 +3437,18 @@ "dev": true, "license": "MIT" }, + "node_modules/@volar/test-utils": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/@volar/test-utils/-/test-utils-2.4.5.tgz", + "integrity": "sha512-/fpjMt5tdGuUlPyWRQr0daq0lkc9XFtnD1VmNJ0N72Q96Lke0JLWWFeywg1gbLFZjy64PHJ7R8l5cdueMGFBDg==", + "dev": true, + "dependencies": { + "@volar/language-core": "2.4.5", + "@volar/language-server": "2.4.5", + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-uri": "^3.0.8" + } + }, "node_modules/@volar/typescript": { "version": "2.4.5", "resolved": "https://registry.npmjs.org/@volar/typescript/-/typescript-2.4.5.tgz", @@ -3358,6 +3461,31 @@ "vscode-uri": "^3.0.8" } }, + "node_modules/@vscode/emmet-helper": { + "version": "2.9.3", + "resolved": "https://registry.npmjs.org/@vscode/emmet-helper/-/emmet-helper-2.9.3.tgz", + "integrity": "sha512-rB39LHWWPQYYlYfpv9qCoZOVioPCftKXXqrsyqN1mTWZM6dTnONT63Db+03vgrBbHzJN45IrgS/AGxw9iiqfEw==", + "dev": true, + "dependencies": { + "emmet": "^2.4.3", + "jsonc-parser": "^2.3.0", + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-languageserver-types": "^3.15.1", + "vscode-uri": "^2.1.2" + } + }, + "node_modules/@vscode/emmet-helper/node_modules/vscode-uri": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz", + "integrity": "sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==", + "dev": true + }, + "node_modules/@vscode/l10n": { + "version": "0.0.18", + "resolved": "https://registry.npmjs.org/@vscode/l10n/-/l10n-0.0.18.tgz", + "integrity": "sha512-KYSIHVmslkaCDyw013pphY+d7x1qV8IZupYfeIfzNA+nsaWHbn5uPuQRvdRFsa9zFzGeudPuoGoZ1Op4jrJXIQ==", + "dev": true + }, "node_modules/@vue/compiler-core": { "version": "3.5.9", "resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.9.tgz", @@ -3507,6 +3635,53 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/@vue/language-server": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@vue/language-server/-/language-server-2.1.6.tgz", + "integrity": "sha512-xRtugvuwFs9KqJ5JMmO9q2b5IrhNLaj/+iqrnBEfWPFRCsywzFABrZFgI7huqsndSdO5uiBkkOkJVcruB0ULFw==", + "dev": true, + "dependencies": { + "@volar/language-core": "~2.4.1", + "@volar/language-server": "~2.4.1", + "@volar/test-utils": "~2.4.1", + "@vue/language-core": "2.1.6", + "@vue/language-service": "2.1.6", + "@vue/typescript-plugin": "2.1.6", + "vscode-languageserver-protocol": "^3.17.5", + "vscode-uri": "^3.0.8" + }, + "bin": { + "vue-language-server": "bin/vue-language-server.js" + } + }, + "node_modules/@vue/language-service": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@vue/language-service/-/language-service-2.1.6.tgz", + "integrity": "sha512-FZ3Fn0MslS/fdBm0U2A/JUmq0HBtvkm/6OcHfw23mE7olm0yCAOV0i8xKqqbrwZeSDoEfk48zzTSEE9Zj6RmBg==", + "dev": true, + "dependencies": { + "@volar/language-core": "~2.4.1", + "@volar/language-service": "~2.4.1", + "@volar/typescript": "~2.4.1", + "@vue/compiler-dom": "^3.4.0", + "@vue/language-core": "2.1.6", + "@vue/shared": "^3.4.0", + "@vue/typescript-plugin": "2.1.6", + "computeds": "^0.0.1", + "path-browserify": "^1.0.1", + "volar-service-css": "0.0.62", + "volar-service-emmet": "0.0.62", + "volar-service-html": "0.0.62", + "volar-service-json": "0.0.62", + "volar-service-pug": "0.0.62", + "volar-service-pug-beautify": "0.0.62", + "volar-service-typescript": "0.0.62", + "volar-service-typescript-twoslash-queries": "0.0.62", + "vscode-html-languageservice": "^5.2.0", + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-uri": "^3.0.8" + } + }, "node_modules/@vue/reactivity": { "version": "3.5.9", "resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.5.9.tgz", @@ -3562,6 +3737,17 @@ "dev": true, "license": "MIT" }, + "node_modules/@vue/typescript-plugin": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@vue/typescript-plugin/-/typescript-plugin-2.1.6.tgz", + "integrity": "sha512-FGwinnIuwZPELbRPZmtA+G4YyLT+lxjGSZQpNvgrzvy3MZBJZzm4UU87DIA7Lb2xbbYpTMAM6P6TAWwioCNZIg==", + "dev": true, + "dependencies": { + "@volar/typescript": "~2.4.1", + "@vue/language-core": "2.1.6", + "@vue/shared": "^3.4.0" + } + }, "node_modules/@vueuse/core": { "version": "11.1.0", "resolved": "https://registry.npmjs.org/@vueuse/core/-/core-11.1.0.tgz", @@ -4453,6 +4639,25 @@ "node": ">=8" } }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dev": true, + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -4551,6 +4756,15 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/character-parser": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz", + "integrity": "sha512-+UqJQjFEFaTAs3bNsF2j2kEN1baG/zghZbdqoYEDxGZtJo9LBzl1A+m0D4n3qKx8N2FNv8/Xp6yV9mQmBuptaw==", + "dev": true, + "dependencies": { + "is-regex": "^1.0.3" + } + }, "node_modules/chardet": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", @@ -5923,6 +6137,23 @@ "node": ">=4" } }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/degenerator": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/degenerator/-/degenerator-5.0.1.tgz", @@ -6025,6 +6256,16 @@ "dev": true, "license": "ISC" }, + "node_modules/emmet": { + "version": "2.4.11", + "resolved": "https://registry.npmjs.org/emmet/-/emmet-2.4.11.tgz", + "integrity": "sha512-23QPJB3moh/U9sT4rQzGgeyyGIrcM+GH5uVYg2C6wZIxAIJq7Ng3QLT79tl8FUwDXhyq9SusfknOrofAKqvgyQ==", + "dev": true, + "dependencies": { + "@emmetio/abbreviation": "^2.3.3", + "@emmetio/css-abbreviation": "^2.1.8" + } + }, "node_modules/end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -6090,6 +6331,27 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es5-shim": { "version": "4.6.7", "resolved": "https://registry.npmjs.org/es5-shim/-/es5-shim-4.6.7.tgz", @@ -7123,6 +7385,25 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dev": true, + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-package-type": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", @@ -7219,6 +7500,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -7250,6 +7543,57 @@ "node": ">=8" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dev": true, + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dev": true, + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/hasha": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.2.tgz", @@ -7647,6 +7991,28 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-expression": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-expression/-/is-expression-4.0.0.tgz", + "integrity": "sha512-zMIXX63sxzG3XrkHkrAPvm/OVZVSCPNkwMHU8oTX7/U3AL78I0QXCEICXUM13BIa8TYGZ68PiTKfQz3yaTNr4A==", + "dev": true, + "dependencies": { + "acorn": "^7.1.1", + "object-assign": "^4.1.1" + } + }, + "node_modules/is-expression/node_modules/acorn": { + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -7730,6 +8096,22 @@ "@types/estree": "*" } }, + "node_modules/is-regex": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", + "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", @@ -8033,6 +8415,12 @@ "node": ">=6" } }, + "node_modules/jsonc-parser": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.3.1.tgz", + "integrity": "sha512-H8jvkz1O50L3dMZCsLqiuB2tA7muqbSg1AtGEkN0leAqGjsUzDJir3Zwr02BhqdcITPg3ei3mZ+HjMocAknhhg==", + "dev": true + }, "node_modules/jsonfile": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", @@ -10330,6 +10718,15 @@ "node": ">=6" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -11060,6 +11457,33 @@ "dev": true, "license": "MIT" }, + "node_modules/pug-error": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/pug-error/-/pug-error-2.1.0.tgz", + "integrity": "sha512-lv7sU9e5Jk8IeUheHata6/UThZ7RK2jnaaNztxfPYUY+VxZyk/ePVaNZ/vwmH8WqGvDz3LrNYt/+gA55NDg6Pg==", + "dev": true + }, + "node_modules/pug-lexer": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pug-lexer/-/pug-lexer-5.0.1.tgz", + "integrity": "sha512-0I6C62+keXlZPZkOJeVam9aBLVP2EnbeDw3An+k0/QlqdwH6rv8284nko14Na7c0TtqtogfWXcRoFE4O4Ff20w==", + "dev": true, + "dependencies": { + "character-parser": "^2.2.0", + "is-expression": "^4.0.0", + "pug-error": "^2.0.0" + } + }, + "node_modules/pug-parser": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/pug-parser/-/pug-parser-6.0.0.tgz", + "integrity": "sha512-ukiYM/9cH6Cml+AOl5kETtM9NR3WulyVP2y4HOU45DyMim1IeP/OOiyEWRr6qk5I5klpsBnbuHpwKmTx6WURnw==", + "dev": true, + "dependencies": { + "pug-error": "^2.0.0", + "token-stream": "1.0.0" + } + }, "node_modules/pump": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz", @@ -11458,6 +11882,12 @@ "node": ">=4" } }, + "node_modules/request-light": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/request-light/-/request-light-0.7.0.tgz", + "integrity": "sha512-lMbBMrDoxgsyO+yB3sDcrDuX85yYt7sS8BfQd11jtbW/z5ZWgLZRcEGLsLoYw7I0WSUGQBs8CC8ScIxkTX1+6Q==", + "dev": true + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -11857,6 +12287,23 @@ "dev": true, "license": "ISC" }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -12697,6 +13144,12 @@ "node": ">=8.0" } }, + "node_modules/token-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/token-stream/-/token-stream-1.0.0.tgz", + "integrity": "sha512-VSsyNPPW74RpHwR8Fc21uubwHY7wMDeJLys2IX5zJNih+OnAnaifKHo+1LHT7DAdloQ7apeaaWg8l7qnf/TnEg==", + "dev": true + }, "node_modules/touch": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", @@ -12862,6 +13315,15 @@ "node": ">=14.17" } }, + "node_modules/typescript-auto-import-cache": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/typescript-auto-import-cache/-/typescript-auto-import-cache-0.3.3.tgz", + "integrity": "sha512-ojEC7+Ci1ij9eE6hp8Jl9VUNnsEKzztktP5gtYNRMrTmfXVwA1PITYYAkpxCvvupdSYa/Re51B6KMcv1CTZEUA==", + "dev": true, + "dependencies": { + "semver": "^7.3.8" + } + }, "node_modules/typescript-eslint": { "version": "8.7.0", "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.7.0.tgz", @@ -13274,6 +13736,196 @@ "@vue/devtools-kit": "^7.4.6" } }, + "node_modules/volar-service-css": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-css/-/volar-service-css-0.0.62.tgz", + "integrity": "sha512-JwNyKsH3F8PuzZYuqPf+2e+4CTU8YoyUHEHVnoXNlrLe7wy9U3biomZ56llN69Ris7TTy/+DEX41yVxQpM4qvg==", + "dev": true, + "dependencies": { + "vscode-css-languageservice": "^6.3.0", + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-uri": "^3.0.8" + }, + "peerDependencies": { + "@volar/language-service": "~2.4.0" + }, + "peerDependenciesMeta": { + "@volar/language-service": { + "optional": true + } + } + }, + "node_modules/volar-service-emmet": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-emmet/-/volar-service-emmet-0.0.62.tgz", + "integrity": "sha512-U4dxWDBWz7Pi4plpbXf4J4Z/ss6kBO3TYrACxWNsE29abu75QzVS0paxDDhI6bhqpbDFXlpsDhZ9aXVFpnfGRQ==", + "dev": true, + "dependencies": { + "@emmetio/css-parser": "^0.4.0", + "@emmetio/html-matcher": "^1.3.0", + "@vscode/emmet-helper": "^2.9.3", + "vscode-uri": "^3.0.8" + }, + "peerDependencies": { + "@volar/language-service": "~2.4.0" + }, + "peerDependenciesMeta": { + "@volar/language-service": { + "optional": true + } + } + }, + "node_modules/volar-service-html": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-html/-/volar-service-html-0.0.62.tgz", + "integrity": "sha512-Zw01aJsZRh4GTGUjveyfEzEqpULQUdQH79KNEiKVYHZyuGtdBRYCHlrus1sueSNMxwwkuF5WnOHfvBzafs8yyQ==", + "dev": true, + "dependencies": { + "vscode-html-languageservice": "^5.3.0", + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-uri": "^3.0.8" + }, + "peerDependencies": { + "@volar/language-service": "~2.4.0" + }, + "peerDependenciesMeta": { + "@volar/language-service": { + "optional": true + } + } + }, + "node_modules/volar-service-json": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-json/-/volar-service-json-0.0.62.tgz", + "integrity": "sha512-Ot+jP+/LzKcaGF7nzrn+gwpzAleb4ej5buO05M8KxfwfODte7o1blARKRoJ3Nv7ls0DBM38Dd5vjzvA9c/9Jtg==", + "dev": true, + "dependencies": { + "vscode-json-languageservice": "^5.4.0", + "vscode-uri": "^3.0.8" + }, + "peerDependencies": { + "@volar/language-service": "~2.4.0" + }, + "peerDependenciesMeta": { + "@volar/language-service": { + "optional": true + } + } + }, + "node_modules/volar-service-pug": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-pug/-/volar-service-pug-0.0.62.tgz", + "integrity": "sha512-C0/O8uGnRfijWKE0zFXxJ/o7BbLebzretsEaiMkvBDIxm5oe7HRDzQr6CgknV/WVgiohZ74v+0CwBPl2YmcPUQ==", + "dev": true, + "dependencies": { + "@volar/language-service": "~2.4.0", + "muggle-string": "^0.4.1", + "pug-lexer": "^5.0.1", + "pug-parser": "^6.0.0", + "volar-service-html": "0.0.62", + "vscode-html-languageservice": "^5.3.0", + "vscode-languageserver-textdocument": "^1.0.11" + } + }, + "node_modules/volar-service-pug-beautify": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-pug-beautify/-/volar-service-pug-beautify-0.0.62.tgz", + "integrity": "sha512-dAFNuNEwTnnVthYoNJhoStwhf/PojzglwCrdhOb2nBegTG3xXMWRFmQzb0JfIlt2wq2wfUq5j+JJswgSD3KluQ==", + "dev": true, + "dependencies": { + "@johnsoncodehk/pug-beautify": "^0.2.2" + }, + "peerDependencies": { + "@volar/language-service": "~2.4.0" + }, + "peerDependenciesMeta": { + "@volar/language-service": { + "optional": true + } + } + }, + "node_modules/volar-service-typescript": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-typescript/-/volar-service-typescript-0.0.62.tgz", + "integrity": "sha512-p7MPi71q7KOsH0eAbZwPBiKPp9B2+qrdHAd6VY5oTo9BUXatsOAdakTm9Yf0DUj6uWBAaOT01BSeVOPwucMV1g==", + "dev": true, + "dependencies": { + "path-browserify": "^1.0.1", + "semver": "^7.6.2", + "typescript-auto-import-cache": "^0.3.3", + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-nls": "^5.2.0", + "vscode-uri": "^3.0.8" + }, + "peerDependencies": { + "@volar/language-service": "~2.4.0" + }, + "peerDependenciesMeta": { + "@volar/language-service": { + "optional": true + } + } + }, + "node_modules/volar-service-typescript-twoslash-queries": { + "version": "0.0.62", + "resolved": "https://registry.npmjs.org/volar-service-typescript-twoslash-queries/-/volar-service-typescript-twoslash-queries-0.0.62.tgz", + "integrity": "sha512-KxFt4zydyJYYI0kFAcWPTh4u0Ha36TASPZkAnNY784GtgajerUqM80nX/W1d0wVhmcOFfAxkVsf/Ed+tiYU7ng==", + "dev": true, + "dependencies": { + "vscode-uri": "^3.0.8" + }, + "peerDependencies": { + "@volar/language-service": "~2.4.0" + }, + "peerDependenciesMeta": { + "@volar/language-service": { + "optional": true + } + } + }, + "node_modules/vscode-css-languageservice": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/vscode-css-languageservice/-/vscode-css-languageservice-6.3.1.tgz", + "integrity": "sha512-1BzTBuJfwMc3A0uX4JBdJgoxp74cjj4q2mDJdp49yD/GuAq4X0k5WtK6fNcMYr+FfJ9nqgR6lpfCSZDkARJ5qQ==", + "dev": true, + "dependencies": { + "@vscode/l10n": "^0.0.18", + "vscode-languageserver-textdocument": "^1.0.12", + "vscode-languageserver-types": "3.17.5", + "vscode-uri": "^3.0.8" + } + }, + "node_modules/vscode-html-languageservice": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/vscode-html-languageservice/-/vscode-html-languageservice-5.3.1.tgz", + "integrity": "sha512-ysUh4hFeW/WOWz/TO9gm08xigiSsV/FOAZ+DolgJfeLftna54YdmZ4A+lIn46RbdO3/Qv5QHTn1ZGqmrXQhZyA==", + "dev": true, + "dependencies": { + "@vscode/l10n": "^0.0.18", + "vscode-languageserver-textdocument": "^1.0.12", + "vscode-languageserver-types": "^3.17.5", + "vscode-uri": "^3.0.8" + } + }, + "node_modules/vscode-json-languageservice": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-5.4.1.tgz", + "integrity": "sha512-5czFGNyVPxz3ZJYl8R3a3SuIj5gjhmGF4Wv05MRPvD4DEnHK6b8km4VbNMJNHBlTCh7A0aHzUbPVzo+0C18mCA==", + "dev": true, + "dependencies": { + "@vscode/l10n": "^0.0.18", + "jsonc-parser": "^3.3.1", + "vscode-languageserver-textdocument": "^1.0.12", + "vscode-languageserver-types": "^3.17.5", + "vscode-uri": "^3.0.8" + } + }, + "node_modules/vscode-json-languageservice/node_modules/jsonc-parser": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", + "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "dev": true + }, "node_modules/vscode-jsonrpc": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz", @@ -13322,6 +13974,12 @@ "dev": true, "license": "MIT" }, + "node_modules/vscode-nls": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.2.0.tgz", + "integrity": "sha512-RAaHx7B14ZU04EU31pT+rKz2/zSl7xMsfIZuo8pd+KZO6PXtQmpevpq3vxvWNcrGbdmhM/rr5Uw5Mz+NBfhVng==", + "dev": true + }, "node_modules/vscode-uri": { "version": "3.0.8", "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.8.tgz", diff --git a/package.json b/package.json index 61a2b285a..19b248575 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "4.22.5", + "version": "4.23.0", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/es/rollup.js", @@ -140,6 +140,7 @@ "@types/node": "^18.19.50", "@types/semver": "^7.5.8", "@types/yargs-parser": "^21.0.3", + "@vue/language-server": "^2.1.6", "acorn": "^8.12.1", "acorn-import-assertions": "^1.9.0", "buble": "^0.20.0", diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index a3a510824..20a0488dd 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -815,8 +815,12 @@ export type WarningHandlerWithDefault = ( export type SerializedTimings = Record; export interface PreRenderedAsset { + /** @deprecated Use "names" instead. */ name: string | undefined; + names: string[]; + /** @deprecated Use "originalFileNames" instead. */ originalFileName: string | null; + originalFileNames: string[]; source: string | Uint8Array; type: 'asset'; } diff --git a/src/utils/FileEmitter.ts b/src/utils/FileEmitter.ts index fcb92de53..2d94a29f8 100644 --- a/src/utils/FileEmitter.ts +++ b/src/utils/FileEmitter.ts @@ -26,27 +26,57 @@ import { logFileNameConflict, logFileReferenceIdNotFoundForFilename, logInvalidRollupPhaseForChunkEmission, - logNoAssetSourceSet + logNoAssetSourceSet, + warnDeprecation } from './logs'; import type { OutputBundleWithPlaceholders } from './outputBundle'; import { FILE_PLACEHOLDER, lowercaseBundleKeys } from './outputBundle'; import { extname } from './path'; import { isPathFragment } from './relativeId'; import { makeUnique, renderNamePattern } from './renderNamePattern'; +import { URL_GENERATEBUNDLE } from './urls'; function generateAssetFileName( name: string | undefined, + names: string[], source: string | Uint8Array, originalFileName: string | null, + originalFileNames: string[], sourceHash: string, outputOptions: NormalizedOutputOptions, - bundle: OutputBundleWithPlaceholders + bundle: OutputBundleWithPlaceholders, + inputOptions: NormalizedInputOptions ): string { const emittedName = outputOptions.sanitizeFileName(name || 'asset'); return makeUnique( renderNamePattern( typeof outputOptions.assetFileNames === 'function' - ? outputOptions.assetFileNames({ name, originalFileName, source, type: 'asset' }) + ? outputOptions.assetFileNames({ + // Additionally, this should be non-enumerable in the next major + get name() { + warnDeprecation( + 'Accessing the "name" property of emitted assets when generating the file name is deprecated. Use the "names" property instead.', + URL_GENERATEBUNDLE, + false, + inputOptions + ); + return name; + }, + names, + // Additionally, this should be non-enumerable in the next major + get originalFileName() { + warnDeprecation( + 'Accessing the "originalFileName" property of emitted assets when generating the file name is deprecated. Use the "originalFileNames" property instead.', + URL_GENERATEBUNDLE, + false, + inputOptions + ); + return originalFileName; + }, + originalFileNames, + source, + type: 'asset' + }) : outputOptions.assetFileNames, 'output.assetFileNames', { @@ -157,7 +187,7 @@ function getChunkFileName( interface FileEmitterOutput { bundle: OutputBundleWithPlaceholders; - fileNamesBySource: Map; + fileNamesBySourceHash: Map; outputOptions: NormalizedOutputOptions; getHash: GetHash; } @@ -262,7 +292,7 @@ export class FileEmitter { const getHash = hasherByType[outputOptions.hashCharacters]; const output = (this.output = { bundle, - fileNamesBySource: new Map(), + fileNamesBySourceHash: new Map(), getHash, outputOptions }); @@ -451,24 +481,27 @@ export class FileEmitter { private finalizeAdditionalAsset( consumedFile: Readonly, source: string | Uint8Array, - { bundle, fileNamesBySource, getHash, outputOptions }: FileEmitterOutput + { bundle, fileNamesBySourceHash, getHash, outputOptions }: FileEmitterOutput ): void { - let { fileName, needsCodeReference, originalFileName, referenceId } = consumedFile; + let { fileName, name, needsCodeReference, originalFileName, referenceId } = consumedFile; // Deduplicate assets if an explicit fileName is not provided if (!fileName) { const sourceHash = getHash(source); - fileName = fileNamesBySource.get(sourceHash); + fileName = fileNamesBySourceHash.get(sourceHash); if (!fileName) { fileName = generateAssetFileName( - consumedFile.name, + name, + name ? [name] : [], source, originalFileName, + originalFileName ? [originalFileName] : [], sourceHash, outputOptions, - bundle + bundle, + this.options ); - fileNamesBySource.set(sourceHash, fileName); + fileNamesBySourceHash.set(sourceHash, fileName); } } @@ -479,12 +512,39 @@ export class FileEmitter { const existingAsset = bundle[fileName]; if (existingAsset?.type === 'asset') { existingAsset.needsCodeReference &&= needsCodeReference; + if (name) { + existingAsset.names.push(name); + } + if (originalFileName) { + existingAsset.originalFileNames.push(originalFileName); + } } else { + const { options } = this; bundle[fileName] = { fileName, - name: consumedFile.name, + get name() { + // Additionally, this should be non-enumerable in the next major + warnDeprecation( + 'Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', + URL_GENERATEBUNDLE, + false, + options + ); + return name; + }, + names: name ? [name] : [], needsCodeReference, - originalFileName, + get originalFileName() { + // Additionally, this should be non-enumerable in the next major + warnDeprecation( + 'Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', + URL_GENERATEBUNDLE, + false, + options + ); + return originalFileName; + }, + originalFileNames: originalFileName ? [originalFileName] : [], source, type: 'asset' }; @@ -494,8 +554,9 @@ export class FileEmitter { private finalizeAssetsWithSameSource( consumedFiles: readonly ConsumedAsset[], sourceHash: string, - { bundle, fileNamesBySource, outputOptions }: FileEmitterOutput + { bundle, fileNamesBySourceHash, outputOptions }: FileEmitterOutput ): void { + const { names, originalFileNames } = getNamesFromAssets(consumedFiles); let fileName = ''; let usedConsumedFile: ConsumedAsset; let needsCodeReference = true; @@ -503,11 +564,14 @@ export class FileEmitter { needsCodeReference &&= consumedFile.needsCodeReference; const assetFileName = generateAssetFileName( consumedFile.name, + names, consumedFile.source!, consumedFile.originalFileName, + originalFileNames, sourceHash, outputOptions, - bundle + bundle, + this.options ); if ( !fileName || @@ -518,7 +582,7 @@ export class FileEmitter { usedConsumedFile = consumedFile; } } - fileNamesBySource.set(sourceHash, fileName); + fileNamesBySourceHash.set(sourceHash, fileName); for (const consumedFile of consumedFiles) { // We must not modify the original assets to avoid interaction between outputs @@ -526,13 +590,55 @@ export class FileEmitter { this.filesByReferenceId.set(consumedFile.referenceId, assetWithFileName); } + const { options } = this; bundle[fileName] = { fileName, - name: usedConsumedFile!.name, + get name() { + // Additionally, this should be non-enumerable in the next major + warnDeprecation( + 'Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', + URL_GENERATEBUNDLE, + false, + options + ); + return usedConsumedFile!.name; + }, + names, needsCodeReference, - originalFileName: usedConsumedFile!.originalFileName, + get originalFileName() { + // Additionally, this should be non-enumerable in the next major + warnDeprecation( + 'Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', + URL_GENERATEBUNDLE, + false, + options + ); + return usedConsumedFile!.originalFileName; + }, + originalFileNames, source: usedConsumedFile!.source!, type: 'asset' }; } } + +function getNamesFromAssets(consumedFiles: readonly ConsumedAsset[]): { + names: string[]; + originalFileNames: string[]; +} { + const names: string[] = []; + const originalFileNames: string[] = []; + for (const { name, originalFileName } of consumedFiles) { + if (typeof name === 'string') { + names.push(name); + } + if (originalFileName) { + originalFileNames.push(originalFileName); + } + } + originalFileNames.sort(); + // Sort by length first and then alphabetically so that the order is stable + // and the shortest names come first + names.sort((a, b) => a.length - b.length || (a > b ? 1 : a === b ? 0 : -1)); + return { names, originalFileNames }; +} diff --git a/src/utils/urls.ts b/src/utils/urls.ts index 75ad400be..13dc372c4 100644 --- a/src/utils/urls.ts +++ b/src/utils/urls.ts @@ -41,6 +41,7 @@ export const URL_CONFIGURATION_FILES = 'command-line-interface/#configuration-fi // plugin-development export const URL_A_SIMPLE_EXAMPLE = 'plugin-development/#a-simple-example'; +export const URL_GENERATEBUNDLE = 'plugin-development/#generatebundle'; export const URL_RENDERDYNAMICIMPORT = 'plugin-development/#renderdynamicimport'; export const URL_THIS_GETMODULEIDS = 'plugin-development/#this-getmoduleids'; export const URL_THIS_GETMODULEINFO = 'plugin-development/#this-getmoduleinfo'; diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_config.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_config.js new file mode 100644 index 000000000..d35c664d5 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_config.js @@ -0,0 +1,80 @@ +const assert = require('node:assert'); +const path = require('node:path'); + +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_DEB = path.join(__dirname, 'deb.js'); + +module.exports = defineTest({ + description: 'supports using a function that returns a pattern for FileNames', + options: { + strictDeprecations: false, + input: ['main.js'], + plugins: { + name: 'test-plugin', + transform(code, id) { + const baseName = path.basename(id); + this.emitFile({ + type: 'asset', + name: `${baseName}.txt`, + originalFileName: baseName, + source: 'hello world' + }); + return null; + } + }, + output: { + entryFileNames: fileInfo => { + assert.deepStrictEqual( + fileInfo, + { + exports: [], + facadeModuleId: ID_MAIN, + isDynamicEntry: false, + isEntry: true, + isImplicitEntry: false, + name: 'main', + moduleIds: [ID_MAIN], + type: 'chunk' + }, + 'entry info' + ); + return `entry-[name]-[hash]-[format].js`; + }, + assetFileNames: fileInfo => { + const originalFileName = fileInfo.originalFileName; + const originalFileNames = ['deb.js', 'main.js']; + assert.ok(originalFileNames.includes(originalFileName), 'original file name'); + assert.deepStrictEqual( + fileInfo, + { + name: `${originalFileName}.txt`, + names: ['deb.js.txt', 'main.js.txt'], + originalFileName, + originalFileNames, + source: 'hello world', + type: 'asset' + }, + 'asset info' + ); + return '[ext]/[hash]-[name][extname]'; + }, + chunkFileNames: fileInfo => { + assert.deepStrictEqual( + fileInfo, + { + exports: ['default'], + facadeModuleId: ID_DEB, + isDynamicEntry: true, + isEntry: false, + isImplicitEntry: false, + moduleIds: [ID_DEB], + name: 'deb', + type: 'chunk' + }, + 'chunk info' + ); + return 'chunk-[name]-[hash]-[format].js'; + } + } + } +}); diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/chunk-deb--Bz6x-oi-amd.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/chunk-deb--Bz6x-oi-amd.js new file mode 100644 index 000000000..e91c726e8 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/chunk-deb--Bz6x-oi-amd.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + var deb = 'string'; + + exports.default = deb; + +})); diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/entry-main-DJVXpS51-amd.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/entry-main-DJVXpS51-amd.js new file mode 100644 index 000000000..0b5f0ae00 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/entry-main-DJVXpS51-amd.js @@ -0,0 +1,6 @@ +define(['require'], (function (require) { 'use strict'; + + console.log('main'); + new Promise(function (resolve, reject) { require(['./chunk-deb--Bz6x-oi-amd'], resolve, reject); }).then(console.log); + +})); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/DHthXMdY-test.txt b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/txt/DHthXMdY-deb.js.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/DHthXMdY-test.txt rename to test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/amd/txt/DHthXMdY-deb.js.txt diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/chunk-deb-9LJjyiap-cjs.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/chunk-deb-9LJjyiap-cjs.js new file mode 100644 index 000000000..f51dbd7a3 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/chunk-deb-9LJjyiap-cjs.js @@ -0,0 +1,5 @@ +'use strict'; + +var deb = 'string'; + +exports.default = deb; diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/entry-main-DFh1DOOW-cjs.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/entry-main-DFh1DOOW-cjs.js new file mode 100644 index 000000000..90ccd092b --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/entry-main-DFh1DOOW-cjs.js @@ -0,0 +1,4 @@ +'use strict'; + +console.log('main'); +Promise.resolve().then(function () { return require('./chunk-deb-9LJjyiap-cjs.js'); }).then(console.log); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/DHthXMdY-test.txt b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/txt/DHthXMdY-deb.js.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/DHthXMdY-test.txt rename to test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/cjs/txt/DHthXMdY-deb.js.txt diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/chunk-deb-H_8j5Qun-es.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/chunk-deb-H_8j5Qun-es.js new file mode 100644 index 000000000..d35400989 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/chunk-deb-H_8j5Qun-es.js @@ -0,0 +1,3 @@ +var deb = 'string'; + +export { deb as default }; diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/entry-main-BeWMkjX8-es.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/entry-main-BeWMkjX8-es.js new file mode 100644 index 000000000..379e421b5 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/entry-main-BeWMkjX8-es.js @@ -0,0 +1,2 @@ +console.log('main'); +import('./chunk-deb-H_8j5Qun-es.js').then(console.log); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/DHthXMdY-test.txt b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/txt/DHthXMdY-deb.js.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/DHthXMdY-test.txt rename to test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/es/txt/DHthXMdY-deb.js.txt diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/chunk-deb-PNqONwrZ-system.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/chunk-deb-PNqONwrZ-system.js new file mode 100644 index 000000000..533f7eb9c --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/chunk-deb-PNqONwrZ-system.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + var deb = exports("default", 'string'); + + }) + }; +})); diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/entry-main-IHNOrI04-system.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/entry-main-IHNOrI04-system.js new file mode 100644 index 000000000..9c91c2d22 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/entry-main-IHNOrI04-system.js @@ -0,0 +1,11 @@ +System.register([], (function (exports, module) { + 'use strict'; + return { + execute: (function () { + + console.log('main'); + module.import('./chunk-deb-PNqONwrZ-system.js').then(console.log); + + }) + }; +})); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/DHthXMdY-test.txt b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/txt/DHthXMdY-deb.js.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/DHthXMdY-test.txt rename to test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/_expected/system/txt/DHthXMdY-deb.js.txt diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/deb.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/deb.js new file mode 100644 index 000000000..25d150df2 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/deb.js @@ -0,0 +1 @@ +export default 'string'; diff --git a/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/main.js b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/main.js new file mode 100644 index 000000000..d2ae8405f --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/filenames-function-patterns/main.js @@ -0,0 +1,2 @@ +console.log('main'); +import('./deb').then(console.log); diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_config.js b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_config.js new file mode 100644 index 000000000..8458b6eed --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_config.js @@ -0,0 +1,53 @@ +const assert = require('node:assert'); + +let referenceIdWithoutName; +let referenceIdWithName; + +module.exports = defineTest({ + description: 'updates asset names when emitting in generate phase', + options: { + strictDeprecations: false, + output: { assetFileNames: 'generated-[name][extname]' }, + plugins: { + renderChunk() { + referenceIdWithoutName = this.emitFile({ + type: 'asset', + source: 'renderChunk-without-names' + }); + referenceIdWithName = this.emitFile({ + type: 'asset', + name: 'with-names.txt', + originalFileName: 'with-names-original.txt', + source: 'renderChunk-with-names' + }); + }, + generateBundle(options, bundle) { + const fileNameWithoutName = this.getFileName(referenceIdWithoutName); + assert.strictEqual(fileNameWithoutName, 'generated-asset'); + assert.strictEqual(bundle[fileNameWithoutName].name, undefined); + assert.strictEqual(bundle[fileNameWithoutName].originalFileName, null); + this.emitFile({ + type: 'asset', + source: 'renderChunk-without-names', + name: 'new-name.txt', + originalFileName: 'original-new-name.txt' + }); + assert.strictEqual(bundle[fileNameWithoutName].name, undefined); + assert.strictEqual(bundle[fileNameWithoutName].originalFileName, null); + + const fileNameWithName = this.getFileName(referenceIdWithName); + assert.strictEqual(fileNameWithName, 'generated-with-names.txt'); + assert.strictEqual(bundle[fileNameWithName].name, 'with-names.txt'); + assert.strictEqual(bundle[fileNameWithName].originalFileName, 'with-names-original.txt'); + this.emitFile({ + type: 'asset', + name: 'second-name.txt', + originalFileName: 'original-second-name.txt', + source: 'renderChunk-with-names' + }); + assert.strictEqual(bundle[fileNameWithName].name, 'with-names.txt'); + assert.strictEqual(bundle[fileNameWithName].originalFileName, 'with-names-original.txt'); + } + } + } +}); diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/generated-asset b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/generated-with-names.txt b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/main.js b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/main.js new file mode 100644 index 000000000..947ad1cba --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/amd/main.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const value = 42; + + exports.value = value; + +})); diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/generated-asset b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/generated-with-names.txt b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/main.js b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/main.js new file mode 100644 index 000000000..9549eb328 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/cjs/main.js @@ -0,0 +1,5 @@ +'use strict'; + +const value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/generated-asset b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/generated-with-names.txt b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/main.js b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/main.js new file mode 100644 index 000000000..d897952f7 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/es/main.js @@ -0,0 +1,3 @@ +const value = 42; + +export { value }; diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/generated-asset b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/generated-with-names.txt b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/main.js b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/main.js new file mode 100644 index 000000000..f80269f90 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/_expected/system/main.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const value = exports("value", 42); + + }) + }; +})); diff --git a/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/main.js b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/main.js new file mode 100644 index 000000000..46d3ca8c6 --- /dev/null +++ b/test/chunking-form/samples/deprecated/emit-file/generate-emission-names/main.js @@ -0,0 +1 @@ +export const value = 42; diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js index 4d3fc03ac..3df57353f 100644 --- a/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js @@ -7,11 +7,19 @@ const ID_DEB = path.join(__dirname, 'deb.js'); module.exports = defineTest({ description: 'supports using a function that returns a pattern for FileNames', options: { + // TODO should be removed with next major as deprecated properties become non-enumerable + strictDeprecations: false, input: ['main.js'], plugins: { name: 'test-plugin', - transform() { - this.emitFile({ type: 'asset', name: 'test.txt', source: 'hello world' }); + transform(code, id) { + const baseName = path.basename(id); + this.emitFile({ + type: 'asset', + name: `${baseName}.txt`, + originalFileName: baseName, + source: 'hello world' + }); return null; } }, @@ -34,11 +42,16 @@ module.exports = defineTest({ return `entry-[name]-[hash]-[format].js`; }, assetFileNames: fileInfo => { + const originalFileName = fileInfo.originalFileName; + const originalFileNames = ['deb.js', 'main.js']; + assert.ok(originalFileNames.includes(originalFileName), 'original file name'); assert.deepStrictEqual( fileInfo, { - name: 'test.txt', - originalFileName: null, + name: `${originalFileName}.txt`, + names: ['deb.js.txt', 'main.js.txt'], + originalFileName, + originalFileNames, source: 'hello world', type: 'asset' }, diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/DHthXMdY-deb.js.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/DHthXMdY-deb.js.txt new file mode 100644 index 000000000..95d09f2b1 --- /dev/null +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/DHthXMdY-deb.js.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/DHthXMdY-deb.js.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/DHthXMdY-deb.js.txt new file mode 100644 index 000000000..95d09f2b1 --- /dev/null +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/DHthXMdY-deb.js.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/DHthXMdY-deb.js.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/DHthXMdY-deb.js.txt new file mode 100644 index 000000000..95d09f2b1 --- /dev/null +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/DHthXMdY-deb.js.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/DHthXMdY-deb.js.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/DHthXMdY-deb.js.txt new file mode 100644 index 000000000..95d09f2b1 --- /dev/null +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/DHthXMdY-deb.js.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_config.js b/test/chunking-form/samples/emit-file/generate-emission-names/_config.js new file mode 100644 index 000000000..196e8b437 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_config.js @@ -0,0 +1,85 @@ +const assert = require('node:assert'); + +let referenceIdWithoutName; +let referenceIdWithName; + +module.exports = defineTest({ + description: 'updates asset names when emitting in generate phase', + options: { + strictDeprecations: false, + output: { assetFileNames: 'generated-[name][extname]' }, + plugins: { + renderChunk() { + referenceIdWithoutName = this.emitFile({ + type: 'asset', + source: 'renderChunk-without-names' + }); + referenceIdWithName = this.emitFile({ + type: 'asset', + name: 'with-names.txt', + originalFileName: 'with-names-original.txt', + source: 'renderChunk-with-names' + }); + }, + generateBundle(options, bundle) { + const fileNameWithoutName = this.getFileName(referenceIdWithoutName); + assert.strictEqual(fileNameWithoutName, 'generated-asset'); + assert.deepStrictEqual(bundle[fileNameWithoutName], { + fileName: 'generated-asset', + name: undefined, + names: [], + needsCodeReference: false, + originalFileName: null, + originalFileNames: [], + source: 'renderChunk-without-names', + type: 'asset' + }); + this.emitFile({ + type: 'asset', + source: 'renderChunk-without-names', + name: 'new-name.txt', + originalFileName: 'original-new-name.txt' + }); + assert.deepStrictEqual(bundle[fileNameWithoutName], { + fileName: 'generated-asset', + name: undefined, + names: ['new-name.txt'], + needsCodeReference: false, + originalFileName: null, + originalFileNames: ['original-new-name.txt'], + source: 'renderChunk-without-names', + type: 'asset' + }); + + const fileNameWithName = this.getFileName(referenceIdWithName); + assert.strictEqual(fileNameWithName, 'generated-with-names.txt'); + assert.deepStrictEqual(bundle[fileNameWithName], { + fileName: 'generated-with-names.txt', + name: 'with-names.txt', + names: ['with-names.txt'], + needsCodeReference: false, + originalFileName: 'with-names-original.txt', + originalFileNames: ['with-names-original.txt'], + source: 'renderChunk-with-names', + type: 'asset' + }); + this.emitFile({ + type: 'asset', + name: 'second-name.txt', + originalFileName: 'original-second-name.txt', + source: 'renderChunk-with-names' + }); + assert.deepStrictEqual(bundle[fileNameWithName], { + fileName: 'generated-with-names.txt', + name: 'with-names.txt', + names: ['with-names.txt', 'second-name.txt'], + needsCodeReference: false, + originalFileName: 'with-names-original.txt', + originalFileNames: ['with-names-original.txt', 'original-second-name.txt'], + source: 'renderChunk-with-names', + type: 'asset' + }); + } + } + } +}); diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/generated-asset b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/generated-with-names.txt b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/main.js b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/main.js new file mode 100644 index 000000000..947ad1cba --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/amd/main.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const value = 42; + + exports.value = value; + +})); diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/generated-asset b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/generated-with-names.txt b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/main.js b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/main.js new file mode 100644 index 000000000..9549eb328 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/cjs/main.js @@ -0,0 +1,5 @@ +'use strict'; + +const value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/generated-asset b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/generated-with-names.txt b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/main.js b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/main.js new file mode 100644 index 000000000..d897952f7 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/es/main.js @@ -0,0 +1,3 @@ +const value = 42; + +export { value }; diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/generated-asset b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/generated-asset new file mode 100644 index 000000000..4a5b37433 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/generated-asset @@ -0,0 +1 @@ +renderChunk-without-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/generated-with-names.txt b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/generated-with-names.txt new file mode 100644 index 000000000..60e4f7f51 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/generated-with-names.txt @@ -0,0 +1 @@ +renderChunk-with-names \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/main.js b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/main.js new file mode 100644 index 000000000..f80269f90 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/_expected/system/main.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const value = exports("value", 42); + + }) + }; +})); diff --git a/test/chunking-form/samples/emit-file/generate-emission-names/main.js b/test/chunking-form/samples/emit-file/generate-emission-names/main.js new file mode 100644 index 000000000..46d3ca8c6 --- /dev/null +++ b/test/chunking-form/samples/emit-file/generate-emission-names/main.js @@ -0,0 +1 @@ +export const value = 42; diff --git a/test/function/samples/deprecated/emit-file/original-file-name/_config.js b/test/function/samples/deprecated/emit-file/original-file-name/_config.js new file mode 100644 index 000000000..f447b06fe --- /dev/null +++ b/test/function/samples/deprecated/emit-file/original-file-name/_config.js @@ -0,0 +1,53 @@ +const assert = require('node:assert'); +const path = require('node:path'); + +const ORIGINAL_FILE_NAME = path.join(__dirname, 'original.txt'); + +module.exports = defineTest({ + description: 'forwards the original file name to other hooks', + options: { + strictDeprecations: false, + output: { + assetFileNames(info) { + if (info.name === 'with_original.txt') { + assert.strictEqual(info.originalFileName, ORIGINAL_FILE_NAME); + } else { + assert.strictEqual(info.originalFileName, null); + } + return info.name; + } + }, + plugins: [ + { + name: 'test', + buildStart() { + this.emitFile({ + type: 'asset', + name: 'with_original.txt', + originalFileName: ORIGINAL_FILE_NAME, + source: 'with original file name' + }); + this.emitFile({ + type: 'asset', + name: 'with_original_null.txt', + originalFileName: null, + source: 'with original file name null' + }); + this.emitFile({ + type: 'asset', + name: 'without_original.txt', + source: 'without original file name' + }); + }, + generateBundle(options, bundle) { + assert.strictEqual(bundle['with_original.txt'].name, 'with_original.txt'); + assert.strictEqual(bundle['with_original.txt'].originalFileName, ORIGINAL_FILE_NAME); + assert.strictEqual(bundle['with_original_null.txt'].name, 'with_original_null.txt'); + assert.strictEqual(bundle['with_original_null.txt'].originalFileName, null); + assert.strictEqual(bundle['without_original.txt'].name, 'without_original.txt'); + assert.strictEqual(bundle['without_original.txt'].originalFileName, null); + } + } + ] + } +}); diff --git a/test/function/samples/deprecated/emit-file/original-file-name/main.js b/test/function/samples/deprecated/emit-file/original-file-name/main.js new file mode 100644 index 000000000..69b8f8f79 --- /dev/null +++ b/test/function/samples/deprecated/emit-file/original-file-name/main.js @@ -0,0 +1,13 @@ +let effect = false; + +var b = { + get a() { + effect = true; + } +}; + +function X() {} +X.prototype = b; +new X().a; + +assert.ok(effect); diff --git a/test/function/samples/deprecated/sourcemap-true-generatebundle/_config.js b/test/function/samples/deprecated/sourcemap-true-generatebundle/_config.js new file mode 100644 index 000000000..c4ce9a2bc --- /dev/null +++ b/test/function/samples/deprecated/sourcemap-true-generatebundle/_config.js @@ -0,0 +1,29 @@ +const assert = require('node:assert'); + +module.exports = defineTest({ + description: 'emits sourcemaps before generateBundle hook', + options: { + strictDeprecations: false, + plugins: [ + { + name: 'test', + generateBundle(options, bundle) { + assert.deepStrictEqual(Object.keys(bundle), ['main.js', 'main.js.map']); + assert.strictEqual( + bundle['main.js'].code, + `'use strict'; + +var main = 42; + +module.exports = main; +//# sourceMappingURL=main.js.map +` + ); + assert.strictEqual(bundle['main.js.map'].name, undefined); + assert.strictEqual(bundle['main.js.map'].originalFileName, null); + } + } + ], + output: { sourcemap: true } + } +}); diff --git a/test/function/samples/deprecated/sourcemap-true-generatebundle/main.js b/test/function/samples/deprecated/sourcemap-true-generatebundle/main.js new file mode 100644 index 000000000..7a4e8a723 --- /dev/null +++ b/test/function/samples/deprecated/sourcemap-true-generatebundle/main.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/function/samples/deprecations/asset-filename-name/_config.js b/test/function/samples/deprecations/asset-filename-name/_config.js new file mode 100644 index 000000000..fa9ea1a19 --- /dev/null +++ b/test/function/samples/deprecations/asset-filename-name/_config.js @@ -0,0 +1,29 @@ +module.exports = defineTest({ + description: 'marks the "name" property of emitted assets as deprecated in assetFileNames', + options: { + output: { + assetFileNames(chunkInfo) { + console.log(chunkInfo.name); + return '[name][extname]'; + } + }, + strictDeprecations: true, + plugins: { + name: 'test', + buildStart() { + this.emitFile({ + type: 'asset', + name: 'test.txt', + originalFileName: 'test.txt', + source: 'test' + }); + } + } + }, + generateError: { + code: 'DEPRECATED_FEATURE', + message: + 'Accessing the "name" property of emitted assets when generating the file name is deprecated. Use the "names" property instead.', + url: 'https://rollupjs.org/plugin-development/#generatebundle' + } +}); diff --git a/test/function/samples/deprecations/asset-filename-name/_expected.js b/test/function/samples/deprecations/asset-filename-name/_expected.js new file mode 100644 index 000000000..2d4172646 --- /dev/null +++ b/test/function/samples/deprecations/asset-filename-name/_expected.js @@ -0,0 +1,6 @@ +import('external'); +import(globalThis.unknown); +import('resolvedString'); +import('resolved-id'); +import('resolved-different'); +import('unresolved'); diff --git a/test/function/samples/deprecations/asset-filename-name/main.js b/test/function/samples/deprecations/asset-filename-name/main.js new file mode 100644 index 000000000..cc1d88a24 --- /dev/null +++ b/test/function/samples/deprecations/asset-filename-name/main.js @@ -0,0 +1 @@ +assert.ok(true); diff --git a/test/function/samples/deprecations/asset-filename-originalfilename/_config.js b/test/function/samples/deprecations/asset-filename-originalfilename/_config.js new file mode 100644 index 000000000..837d4ab10 --- /dev/null +++ b/test/function/samples/deprecations/asset-filename-originalfilename/_config.js @@ -0,0 +1,29 @@ +module.exports = defineTest({ + description: 'marks the "name" property of emitted assets as deprecated in assetFileNames', + options: { + output: { + assetFileNames(chunkInfo) { + console.log(chunkInfo.originalFileName); + return '[name][extname]'; + } + }, + strictDeprecations: true, + plugins: { + name: 'test', + buildStart() { + this.emitFile({ + type: 'asset', + name: 'test.txt', + originalFileName: 'test.txt', + source: 'test' + }); + } + } + }, + generateError: { + code: 'DEPRECATED_FEATURE', + message: + 'Accessing the "originalFileName" property of emitted assets when generating the file name is deprecated. Use the "originalFileNames" property instead.', + url: 'https://rollupjs.org/plugin-development/#generatebundle' + } +}); diff --git a/test/function/samples/deprecations/asset-filename-originalfilename/_expected.js b/test/function/samples/deprecations/asset-filename-originalfilename/_expected.js new file mode 100644 index 000000000..2d4172646 --- /dev/null +++ b/test/function/samples/deprecations/asset-filename-originalfilename/_expected.js @@ -0,0 +1,6 @@ +import('external'); +import(globalThis.unknown); +import('resolvedString'); +import('resolved-id'); +import('resolved-different'); +import('unresolved'); diff --git a/test/function/samples/deprecations/asset-filename-originalfilename/main.js b/test/function/samples/deprecations/asset-filename-originalfilename/main.js new file mode 100644 index 000000000..cc1d88a24 --- /dev/null +++ b/test/function/samples/deprecations/asset-filename-originalfilename/main.js @@ -0,0 +1 @@ +assert.ok(true); diff --git a/test/function/samples/deprecations/asset-name-in-bundle/_config.js b/test/function/samples/deprecations/asset-name-in-bundle/_config.js new file mode 100644 index 000000000..373003886 --- /dev/null +++ b/test/function/samples/deprecations/asset-name-in-bundle/_config.js @@ -0,0 +1,30 @@ +module.exports = defineTest({ + description: 'marks the "name" property of emitted assets as deprecated in generateBundle', + options: { + output: { assetFileNames: '[name][extname]' }, + strictDeprecations: true, + plugins: { + name: 'test', + buildStart() { + this.emitFile({ + type: 'asset', + name: 'test.txt', + originalFileName: 'test.txt', + source: 'test' + }); + }, + generateBundle(options, bundle) { + console.log(bundle['test.txt'].name); + } + } + }, + generateError: { + code: 'PLUGIN_ERROR', + hook: 'generateBundle', + message: + 'Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', + plugin: 'test', + pluginCode: 'DEPRECATED_FEATURE', + url: 'https://rollupjs.org/plugin-development/#generatebundle' + } +}); diff --git a/test/function/samples/deprecations/asset-name-in-bundle/_expected.js b/test/function/samples/deprecations/asset-name-in-bundle/_expected.js new file mode 100644 index 000000000..2d4172646 --- /dev/null +++ b/test/function/samples/deprecations/asset-name-in-bundle/_expected.js @@ -0,0 +1,6 @@ +import('external'); +import(globalThis.unknown); +import('resolvedString'); +import('resolved-id'); +import('resolved-different'); +import('unresolved'); diff --git a/test/function/samples/deprecations/asset-name-in-bundle/main.js b/test/function/samples/deprecations/asset-name-in-bundle/main.js new file mode 100644 index 000000000..cc1d88a24 --- /dev/null +++ b/test/function/samples/deprecations/asset-name-in-bundle/main.js @@ -0,0 +1 @@ +assert.ok(true); diff --git a/test/function/samples/deprecations/asset-originalfilename-in-bundle/_config.js b/test/function/samples/deprecations/asset-originalfilename-in-bundle/_config.js new file mode 100644 index 000000000..9b25343cf --- /dev/null +++ b/test/function/samples/deprecations/asset-originalfilename-in-bundle/_config.js @@ -0,0 +1,31 @@ +module.exports = defineTest({ + description: + 'marks the "originalFileName" property of emitted assets as deprecated in generateBundle', + options: { + output: { assetFileNames: '[name][extname]' }, + strictDeprecations: true, + plugins: { + name: 'test', + buildStart() { + this.emitFile({ + type: 'asset', + name: 'test.txt', + originalFileName: 'test.txt', + source: 'test' + }); + }, + generateBundle(options, bundle) { + console.log(bundle['test.txt'].originalFileName); + } + } + }, + generateError: { + code: 'PLUGIN_ERROR', + hook: 'generateBundle', + message: + 'Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', + plugin: 'test', + pluginCode: 'DEPRECATED_FEATURE', + url: 'https://rollupjs.org/plugin-development/#generatebundle' + } +}); diff --git a/test/function/samples/deprecations/asset-originalfilename-in-bundle/_expected.js b/test/function/samples/deprecations/asset-originalfilename-in-bundle/_expected.js new file mode 100644 index 000000000..2d4172646 --- /dev/null +++ b/test/function/samples/deprecations/asset-originalfilename-in-bundle/_expected.js @@ -0,0 +1,6 @@ +import('external'); +import(globalThis.unknown); +import('resolvedString'); +import('resolved-id'); +import('resolved-different'); +import('unresolved'); diff --git a/test/function/samples/deprecations/asset-originalfilename-in-bundle/main.js b/test/function/samples/deprecations/asset-originalfilename-in-bundle/main.js new file mode 100644 index 000000000..cc1d88a24 --- /dev/null +++ b/test/function/samples/deprecations/asset-originalfilename-in-bundle/main.js @@ -0,0 +1 @@ +assert.ok(true); diff --git a/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/_config.js b/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/_config.js new file mode 100644 index 000000000..389aee517 --- /dev/null +++ b/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/_config.js @@ -0,0 +1,31 @@ +module.exports = defineTest({ + description: + 'marks the "name" property of emitted assets as deprecated in generateBundle when emitted during generate phase', + options: { + output: { assetFileNames: '[name][extname]' }, + strictDeprecations: true, + plugins: { + name: 'test', + renderChunk() { + this.emitFile({ + type: 'asset', + name: 'test.txt', + originalFileName: 'test.txt', + source: 'test' + }); + }, + generateBundle(options, bundle) { + console.log(bundle['test.txt'].name); + } + } + }, + generateError: { + code: 'PLUGIN_ERROR', + hook: 'generateBundle', + message: + 'Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', + plugin: 'test', + pluginCode: 'DEPRECATED_FEATURE', + url: 'https://rollupjs.org/plugin-development/#generatebundle' + } +}); diff --git a/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/_expected.js b/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/_expected.js new file mode 100644 index 000000000..2d4172646 --- /dev/null +++ b/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/_expected.js @@ -0,0 +1,6 @@ +import('external'); +import(globalThis.unknown); +import('resolvedString'); +import('resolved-id'); +import('resolved-different'); +import('unresolved'); diff --git a/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/main.js b/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/main.js new file mode 100644 index 000000000..cc1d88a24 --- /dev/null +++ b/test/function/samples/deprecations/asset-render-chunk-name-in-bundle/main.js @@ -0,0 +1 @@ +assert.ok(true); diff --git a/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/_config.js b/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/_config.js new file mode 100644 index 000000000..c16ba0cdd --- /dev/null +++ b/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/_config.js @@ -0,0 +1,31 @@ +module.exports = defineTest({ + description: + 'marks the "originalFileName" property of emitted assets as deprecated in generateBundle when emitted during generate phase', + options: { + output: { assetFileNames: '[name][extname]' }, + strictDeprecations: true, + plugins: { + name: 'test', + renderChunk() { + this.emitFile({ + type: 'asset', + name: 'test.txt', + originalFileName: 'test.txt', + source: 'test' + }); + }, + generateBundle(options, bundle) { + console.log(bundle['test.txt'].originalFileName); + } + } + }, + generateError: { + code: 'PLUGIN_ERROR', + hook: 'generateBundle', + message: + 'Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', + plugin: 'test', + pluginCode: 'DEPRECATED_FEATURE', + url: 'https://rollupjs.org/plugin-development/#generatebundle' + } +}); diff --git a/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/_expected.js b/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/_expected.js new file mode 100644 index 000000000..2d4172646 --- /dev/null +++ b/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/_expected.js @@ -0,0 +1,6 @@ +import('external'); +import(globalThis.unknown); +import('resolvedString'); +import('resolved-id'); +import('resolved-different'); +import('unresolved'); diff --git a/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/main.js b/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/main.js new file mode 100644 index 000000000..cc1d88a24 --- /dev/null +++ b/test/function/samples/deprecations/asset-render-chunk-originalfilename-in-bundle/main.js @@ -0,0 +1 @@ +assert.ok(true); diff --git a/test/function/samples/emit-file/original-file-name/_config.js b/test/function/samples/emit-file/original-file-name/_config.js index 6ca9ba6db..0463b2356 100644 --- a/test/function/samples/emit-file/original-file-name/_config.js +++ b/test/function/samples/emit-file/original-file-name/_config.js @@ -8,12 +8,12 @@ module.exports = defineTest({ options: { output: { assetFileNames(info) { - if (info.name === 'with_original.txt') { - assert.strictEqual(info.originalFileName, ORIGINAL_FILE_NAME); + if (info.names.includes('with_original.txt')) { + assert.deepStrictEqual(info.originalFileNames, [ORIGINAL_FILE_NAME]); } else { - assert.strictEqual(info.originalFileName, null); + assert.deepStrictEqual(info.originalFileNames, []); } - return info.name; + return info.names[0]; } }, plugins: [ @@ -39,9 +39,11 @@ module.exports = defineTest({ }); }, generateBundle(options, bundle) { - assert.strictEqual(bundle['with_original.txt'].originalFileName, ORIGINAL_FILE_NAME); - assert.strictEqual(bundle['with_original_null.txt'].originalFileName, null); - assert.strictEqual(bundle['without_original.txt'].originalFileName, null); + assert.deepStrictEqual(bundle['with_original.txt'].originalFileNames, [ + ORIGINAL_FILE_NAME + ]); + assert.deepStrictEqual(bundle['with_original_null.txt'].originalFileNames, []); + assert.deepStrictEqual(bundle['without_original.txt'].originalFileNames, []); } } ] diff --git a/test/function/samples/emit-file/original-file-names/_config.js b/test/function/samples/emit-file/original-file-names/_config.js new file mode 100644 index 000000000..2abe1bc28 --- /dev/null +++ b/test/function/samples/emit-file/original-file-names/_config.js @@ -0,0 +1,85 @@ +const assert = require('node:assert'); +const path = require('node:path'); + +const ORIGINAL_FILE_NAME_1 = path.join(__dirname, 'original.txt'); +const ORIGINAL_FILE_NAME_2A = path.join(__dirname, 'original2a.txt'); +const ORIGINAL_FILE_NAME_2B = path.join(__dirname, 'original2b.txt'); + +module.exports = defineTest({ + description: 'forwards the original file name to other hooks', + options: { + output: { + assetFileNames({ names, originalFileNames, source }) { + switch (source) { + case 'with original file name': + assert.deepEqual(names, ['with_original.txt']); + assert.deepEqual(originalFileNames, [ORIGINAL_FILE_NAME_1]); + break; + case 'with multiple original file names': + assert.deepEqual(names, [ + 'with_multiple_original_a.txt', + 'with_multiple_original_b.txt' + ]); + assert.deepEqual(originalFileNames, [ORIGINAL_FILE_NAME_2A, ORIGINAL_FILE_NAME_2B]); + break; + case 'with original file name null': + assert.deepEqual(names, ['with_original_null.txt']); + assert.deepEqual(originalFileNames, []); + break; + case 'without original file name': + assert.deepEqual(names, ['without_original.txt']); + assert.deepEqual(originalFileNames, []); + break; + default: + throw new Error(`Unexpected source: ${source}`); + } + return names[0]; + } + }, + plugins: [ + { + name: 'test', + buildStart() { + this.emitFile({ + type: 'asset', + name: 'with_original.txt', + originalFileName: ORIGINAL_FILE_NAME_1, + source: 'with original file name' + }); + this.emitFile({ + type: 'asset', + name: 'with_multiple_original_a.txt', + originalFileName: ORIGINAL_FILE_NAME_2A, + source: 'with multiple original file names' + }); + this.emitFile({ + type: 'asset', + name: 'with_multiple_original_b.txt', + originalFileName: ORIGINAL_FILE_NAME_2B, + source: 'with multiple original file names' + }); + this.emitFile({ + type: 'asset', + name: 'with_original_null.txt', + originalFileName: null, + source: 'with original file name null' + }); + this.emitFile({ + type: 'asset', + name: 'without_original.txt', + source: 'without original file name' + }); + }, + generateBundle(options, bundle) { + assert.deepEqual(bundle['with_original.txt'].originalFileNames, [ORIGINAL_FILE_NAME_1]); + assert.deepEqual(bundle['with_multiple_original_a.txt'].originalFileNames, [ + ORIGINAL_FILE_NAME_2A, + ORIGINAL_FILE_NAME_2B + ]); + assert.deepEqual(bundle['with_original_null.txt'].originalFileNames, []); + assert.deepEqual(bundle['without_original.txt'].originalFileNames, []); + } + } + ] + } +}); diff --git a/test/function/samples/emit-file/original-file-names/main.js b/test/function/samples/emit-file/original-file-names/main.js new file mode 100644 index 000000000..69b8f8f79 --- /dev/null +++ b/test/function/samples/emit-file/original-file-names/main.js @@ -0,0 +1,13 @@ +let effect = false; + +var b = { + get a() { + effect = true; + } +}; + +function X() {} +X.prototype = b; +new X().a; + +assert.ok(effect); diff --git a/test/function/samples/sourcemap-true-generatebundle/_config.js b/test/function/samples/sourcemap-true-generatebundle/_config.js index ee20d78a9..706335b2f 100644 --- a/test/function/samples/sourcemap-true-generatebundle/_config.js +++ b/test/function/samples/sourcemap-true-generatebundle/_config.js @@ -3,6 +3,8 @@ const assert = require('node:assert'); module.exports = defineTest({ description: 'emits sourcemaps before generateBundle hook', options: { + // TODO should be removed with next major as deprecated properties become non-enumerable + strictDeprecations: false, plugins: [ { name: 'test', @@ -21,8 +23,10 @@ module.exports = main; assert.deepStrictEqual(bundle['main.js.map'], { fileName: 'main.js.map', name: undefined, + names: [], needsCodeReference: false, originalFileName: null, + originalFileNames: [], source: '{"version":3,"file":"main.js","sources":["main.js"],"sourcesContent":["export default 42;\\n"],"names":[],"mappings":";;AAAA,WAAe,EAAE;;;;"}', type: 'asset' diff --git a/test/utils.js b/test/utils.js index 361a5ca4c..43f1dcb75 100644 --- a/test/utils.js +++ b/test/utils.js @@ -86,14 +86,14 @@ function normaliseError(error) { * @param {RollupError} expected */ exports.compareError = function compareError(actual, expected) { - if (actual.stack) { - assert.ok(actual.stack.includes(expected.message)); - } actual = normaliseError(actual); if (expected.frame) { expected.frame = deindent(expected.frame); } assert.deepEqual(actual, expected); + if (actual.stack) { + assert.ok(actual.stack.includes(expected.message)); + } }; /**