From 4760738f0fa85627a8b51703891250e43690921a Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Sun, 28 Aug 2022 20:06:01 +0900 Subject: [PATCH 1/6] refactor(create-vite): move index.js --- packages/create-vite/package.json | 6 +++--- packages/create-vite/{ => src}/index.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename packages/create-vite/{ => src}/index.js (99%) diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index a52fa837d977ab..c6a8b9601a43a5 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -5,14 +5,14 @@ "license": "MIT", "author": "Evan You", "bin": { - "create-vite": "index.js", - "cva": "index.js" + "create-vite": "src/index.js", + "cva": "src/index.js" }, "files": [ "index.js", "template-*" ], - "main": "index.js", + "main": "src/index.js", "engines": { "node": "^14.18.0 || >=16.0.0" }, diff --git a/packages/create-vite/index.js b/packages/create-vite/src/index.js similarity index 99% rename from packages/create-vite/index.js rename to packages/create-vite/src/index.js index d602eea2b3e57a..1065bd7a6470b6 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/src/index.js @@ -307,7 +307,7 @@ async function init() { const templateDir = path.resolve( fileURLToPath(import.meta.url), - '..', + '../..', `template-${template}` ) From ae6995095337560ffa3cbb68bac57030faf5c43b Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Sun, 28 Aug 2022 20:07:58 +0900 Subject: [PATCH 2/6] refactor(create-vite): split entrypoint --- packages/create-vite/index.js | 3 +++ packages/create-vite/package.json | 6 +++--- packages/create-vite/src/index.js | 2 -- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100755 packages/create-vite/index.js diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js new file mode 100755 index 00000000000000..bb1e41a6d42636 --- /dev/null +++ b/packages/create-vite/index.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +import './src/index.js' diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index c6a8b9601a43a5..a52fa837d977ab 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -5,14 +5,14 @@ "license": "MIT", "author": "Evan You", "bin": { - "create-vite": "src/index.js", - "cva": "src/index.js" + "create-vite": "index.js", + "cva": "index.js" }, "files": [ "index.js", "template-*" ], - "main": "src/index.js", + "main": "index.js", "engines": { "node": "^14.18.0 || >=16.0.0" }, diff --git a/packages/create-vite/src/index.js b/packages/create-vite/src/index.js index 1065bd7a6470b6..8e5aa02ff4a40e 100755 --- a/packages/create-vite/src/index.js +++ b/packages/create-vite/src/index.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - // @ts-check import fs from 'node:fs' import path from 'node:path' From a739a5380717aceec38a52893a378c1e5e17c564 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 11 Jul 2022 08:46:47 +0900 Subject: [PATCH 3/6] perf(create-vite): bundle and minify --- packages/create-vite/build.config.ts | 11 +++++++++++ packages/create-vite/index.js | 2 +- packages/create-vite/package.json | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/create-vite/build.config.ts diff --git a/packages/create-vite/build.config.ts b/packages/create-vite/build.config.ts new file mode 100644 index 00000000000000..ce0e9ef32548f0 --- /dev/null +++ b/packages/create-vite/build.config.ts @@ -0,0 +1,11 @@ +import { defineBuildConfig } from 'unbuild' + +export default defineBuildConfig({ + entries: ['src/index'], + clean: true, + rollup: { + esbuild: { + minify: true + } + } +}) diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js index bb1e41a6d42636..f5e8e064a68d9f 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/index.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -import './src/index.js' +import './dist/index.mjs' diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index a52fa837d977ab..1f8487a56584a8 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -10,9 +10,15 @@ }, "files": [ "index.js", - "template-*" + "template-*", + "dist" ], "main": "index.js", + "scripts": { + "dev": "unbuild --stub", + "build": "unbuild", + "prepublishOnly": "npm run build" + }, "engines": { "node": "^14.18.0 || >=16.0.0" }, From a5c2bbda2d31c4d6189426c3ad73747d07ee7412 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 11 Jul 2022 12:04:12 +0900 Subject: [PATCH 4/6] chore: extract license plugin --- .eslintrc.cjs | 2 +- package.json | 3 + packages/vite/package.json | 1 - packages/vite/rollup.config.ts | 115 +----------------------------- pnpm-lock.yaml | 12 ++-- scripts/rollupLicensePlugin.mjs | 121 ++++++++++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 120 deletions(-) create mode 100644 scripts/rollupLicensePlugin.mjs diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 12ae8a255406d4..e14beca6015d94 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -178,7 +178,7 @@ module.exports = defineConfig({ } }, { - files: ['*.js'], + files: ['*.js', '*.mjs', '*.cjs'], rules: { '@typescript-eslint/explicit-module-boundary-types': 'off' } diff --git a/package.json b/package.json index 04df3123ff8c6d..5ecbd6f517ea1b 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "eslint-plugin-import": "^2.26.0", "eslint-plugin-node": "^11.1.0", "execa": "^6.1.0", + "fast-glob": "^3.2.11", "fs-extra": "^10.1.0", "lint-staged": "^13.0.3", "minimist": "^1.2.6", @@ -76,8 +77,10 @@ "pnpm": "^7.9.3", "prettier": "2.7.1", "prompts": "^2.4.2", + "resolve": "^1.22.1", "rimraf": "^3.0.2", "rollup": "~2.78.0", + "rollup-plugin-license": "^2.8.1", "semver": "^7.3.7", "simple-git-hooks": "^2.8.0", "tslib": "^2.4.0", diff --git a/packages/vite/package.json b/packages/vite/package.json index ceb4d2810068f4..318abeb6d233f7 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -109,7 +109,6 @@ "postcss-load-config": "^4.0.1", "postcss-modules": "^5.0.0", "resolve.exports": "^1.1.0", - "rollup-plugin-license": "^2.8.1", "sirv": "^2.0.2", "source-map-js": "^1.0.2", "source-map-support": "^0.5.21", diff --git a/packages/vite/rollup.config.ts b/packages/vite/rollup.config.ts index bf5c0e9da810a2..0352654f2316ca 100644 --- a/packages/vite/rollup.config.ts +++ b/packages/vite/rollup.config.ts @@ -1,17 +1,13 @@ /* eslint-disable no-restricted-globals */ -import fs from 'node:fs' import path from 'node:path' import nodeResolve from '@rollup/plugin-node-resolve' import typescript from '@rollup/plugin-typescript' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' -import license from 'rollup-plugin-license' import MagicString from 'magic-string' -import colors from 'picocolors' -import fg from 'fast-glob' -import { sync as resolve } from 'resolve' import type { Plugin, RollupOptions } from 'rollup' import { defineConfig } from 'rollup' +import licensePlugin from '../../scripts/rollupLicensePlugin.mjs' import pkg from './package.json' const envConfig = defineConfig({ @@ -256,115 +252,6 @@ function shimDepsPlugin(deps: Record): Plugin { } } -function licensePlugin() { - return license({ - thirdParty(dependencies) { - // https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js - // MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md - const coreLicense = fs.readFileSync( - path.resolve(__dirname, '../../LICENSE') - ) - function sortLicenses(licenses) { - let withParenthesis = [] - let noParenthesis = [] - licenses.forEach((license) => { - if (/^\(/.test(license)) { - withParenthesis.push(license) - } else { - noParenthesis.push(license) - } - }) - withParenthesis = withParenthesis.sort() - noParenthesis = noParenthesis.sort() - return [...noParenthesis, ...withParenthesis] - } - const licenses = new Set() - const dependencyLicenseTexts = dependencies - .sort(({ name: nameA }, { name: nameB }) => - nameA > nameB ? 1 : nameB > nameA ? -1 : 0 - ) - .map( - ({ - name, - license, - licenseText, - author, - maintainers, - contributors, - repository - }) => { - let text = `## ${name}\n` - if (license) { - text += `License: ${license}\n` - } - const names = new Set() - for (const person of [author, ...maintainers, ...contributors]) { - const name = typeof person === 'string' ? person : person?.name - if (name) { - names.add(name) - } - } - if (names.size > 0) { - text += `By: ${Array.from(names).join(', ')}\n` - } - if (repository) { - text += `Repository: ${ - typeof repository === 'string' ? repository : repository.url - }\n` - } - if (!licenseText) { - try { - const pkgDir = path.dirname( - resolve(path.join(name, 'package.json'), { - preserveSymlinks: false - }) - ) - const licenseFile = fg.sync(`${pkgDir}/LICENSE*`, { - caseSensitiveMatch: false - })[0] - if (licenseFile) { - licenseText = fs.readFileSync(licenseFile, 'utf-8') - } - } catch {} - } - if (licenseText) { - text += - '\n' + - licenseText - .trim() - .replace(/(\r\n|\r)/gm, '\n') - .split('\n') - .map((line) => `> ${line}`) - .join('\n') + - '\n' - } - licenses.add(license) - return text - } - ) - .join('\n---------------------------------------\n\n') - const licenseText = - `# Vite core license\n` + - `Vite is released under the MIT license:\n\n` + - coreLicense + - `\n# Licenses of bundled dependencies\n` + - `The published Vite artifact additionally contains code with the following licenses:\n` + - `${sortLicenses(licenses).join(', ')}\n\n` + - `# Bundled dependencies:\n` + - dependencyLicenseTexts - const existingLicenseText = fs.readFileSync('LICENSE.md', 'utf8') - if (existingLicenseText !== licenseText) { - fs.writeFileSync('LICENSE.md', licenseText) - console.warn( - colors.yellow( - '\nLICENSE.md updated. You should commit the updated file.\n' - ) - ) - } - } - }) -} - /** * Inject CJS Context for each deps chunk */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5e3a95a317cd7..72754c2cf360fe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,6 +41,7 @@ importers: eslint-plugin-import: ^2.26.0 eslint-plugin-node: ^11.1.0 execa: ^6.1.0 + fast-glob: ^3.2.11 fs-extra: ^10.1.0 lint-staged: ^13.0.3 minimist: ^1.2.6 @@ -50,8 +51,10 @@ importers: pnpm: ^7.9.3 prettier: 2.7.1 prompts: ^2.4.2 + resolve: ^1.22.1 rimraf: ^3.0.2 rollup: ~2.78.0 + rollup-plugin-license: ^2.8.1 semver: ^7.3.7 simple-git-hooks: ^2.8.0 tslib: ^2.4.0 @@ -94,6 +97,7 @@ importers: eslint-plugin-import: 2.26.0_3bh5nkk7utn7e74vrwtv6rxmt4 eslint-plugin-node: 11.1.0_eslint@8.22.0 execa: 6.1.0 + fast-glob: 3.2.11 fs-extra: 10.1.0 lint-staged: 13.0.3 minimist: 1.2.6 @@ -103,8 +107,10 @@ importers: pnpm: 7.9.3 prettier: 2.7.1 prompts: 2.4.2 + resolve: 1.22.1 rimraf: 3.0.2 rollup: 2.78.0 + rollup-plugin-license: 2.8.1_rollup@2.78.0 semver: 7.3.7 simple-git-hooks: 2.8.0 tslib: 2.4.0 @@ -252,7 +258,6 @@ importers: resolve: ^1.22.1 resolve.exports: ^1.1.0 rollup: ~2.78.0 - rollup-plugin-license: ^2.8.1 sirv: ^2.0.2 source-map-js: ^1.0.2 source-map-support: ^0.5.21 @@ -313,7 +318,6 @@ importers: postcss-load-config: 4.0.1_postcss@8.4.16 postcss-modules: 5.0.0_postcss@8.4.16 resolve.exports: 1.1.0 - rollup-plugin-license: 2.8.1_rollup@2.78.0 sirv: 2.0.2 source-map-js: 1.0.2 source-map-support: 0.5.21 @@ -5039,7 +5043,7 @@ packages: is-glob: 4.0.3 minimatch: 3.1.2 object.values: 1.1.5 - resolve: 1.22.0 + resolve: 1.22.1 tsconfig-paths: 3.14.1 transitivePeerDependencies: - eslint-import-resolver-typescript @@ -5058,7 +5062,7 @@ packages: eslint-utils: 2.1.0 ignore: 5.2.0 minimatch: 3.1.2 - resolve: 1.22.0 + resolve: 1.22.1 semver: 6.3.0 dev: true diff --git a/scripts/rollupLicensePlugin.mjs b/scripts/rollupLicensePlugin.mjs new file mode 100644 index 00000000000000..a6dddf4baca45c --- /dev/null +++ b/scripts/rollupLicensePlugin.mjs @@ -0,0 +1,121 @@ +// @ts-check + +import fs from 'node:fs' +import path from 'node:path' +import license from 'rollup-plugin-license' +import colors from 'picocolors' +import fg from 'fast-glob' +import { sync as resolve } from 'resolve' + +function licensePlugin() { + return license({ + thirdParty(dependencies) { + // https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js + // MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md + const coreLicense = fs.readFileSync( + new URL('../LICENSE', import.meta.url) + ) + function sortLicenses(licenses) { + let withParenthesis = [] + let noParenthesis = [] + licenses.forEach((license) => { + if (/^\(/.test(license)) { + withParenthesis.push(license) + } else { + noParenthesis.push(license) + } + }) + withParenthesis = withParenthesis.sort() + noParenthesis = noParenthesis.sort() + return [...noParenthesis, ...withParenthesis] + } + const licenses = new Set() + const dependencyLicenseTexts = dependencies + .sort(({ name: _nameA }, { name: _nameB }) => { + const nameA = /** @type {string} */ (_nameA) + const nameB = /** @type {string} */ (_nameB) + return nameA > nameB ? 1 : nameB > nameA ? -1 : 0 + }) + .map( + ({ + name, + license, + licenseText, + author, + maintainers, + contributors, + repository + }) => { + let text = `## ${name}\n` + if (license) { + text += `License: ${license}\n` + } + const names = new Set() + for (const person of [author, ...maintainers, ...contributors]) { + const name = typeof person === 'string' ? person : person?.name + if (name) { + names.add(name) + } + } + if (names.size > 0) { + text += `By: ${Array.from(names).join(', ')}\n` + } + if (repository) { + text += `Repository: ${ + typeof repository === 'string' ? repository : repository.url + }\n` + } + if (!licenseText && name) { + try { + const pkgDir = path.dirname( + resolve(path.join(name, 'package.json'), { + preserveSymlinks: false + }) + ) + const licenseFile = fg.sync(`${pkgDir}/LICENSE*`, { + caseSensitiveMatch: false + })[0] + if (licenseFile) { + licenseText = fs.readFileSync(licenseFile, 'utf-8') + } + } catch {} + } + if (licenseText) { + text += + '\n' + + licenseText + .trim() + .replace(/(\r\n|\r)/gm, '\n') + .split('\n') + .map((line) => `> ${line}`) + .join('\n') + + '\n' + } + licenses.add(license) + return text + } + ) + .join('\n---------------------------------------\n\n') + const licenseText = + `# Vite core license\n` + + `Vite is released under the MIT license:\n\n` + + coreLicense + + `\n# Licenses of bundled dependencies\n` + + `The published Vite artifact additionally contains code with the following licenses:\n` + + `${sortLicenses(licenses).join(', ')}\n\n` + + `# Bundled dependencies:\n` + + dependencyLicenseTexts + const existingLicenseText = fs.readFileSync('LICENSE.md', 'utf8') + if (existingLicenseText !== licenseText) { + fs.writeFileSync('LICENSE.md', licenseText) + console.warn( + colors.yellow( + '\nLICENSE.md updated. You should commit the updated file.\n' + ) + ) + } + } + }) +} + +export default licensePlugin From b8cc43476f7876cf4d46804b46a9019e3a2f28fe Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 11 Jul 2022 12:13:43 +0900 Subject: [PATCH 5/6] perf(create-vite): bundle deps --- packages/create-vite/LICENSE | 274 +++++++++++++++++++++++++++ packages/create-vite/build.config.ts | 20 ++ packages/create-vite/package.json | 2 +- packages/vite/rollup.config.ts | 7 +- pnpm-lock.yaml | 13 +- scripts/rollupLicensePlugin.mjs | 17 +- 6 files changed, 323 insertions(+), 10 deletions(-) diff --git a/packages/create-vite/LICENSE b/packages/create-vite/LICENSE index 9c1b313d7b1816..4851bee9f284f3 100644 --- a/packages/create-vite/LICENSE +++ b/packages/create-vite/LICENSE @@ -1,3 +1,6 @@ +# create-vite license +create-vite is released under the MIT license: + MIT License Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors @@ -19,3 +22,274 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# Licenses of bundled dependencies +The published create-vite artifact additionally contains code with the following licenses: +ISC, MIT + +# Bundled dependencies: +## cross-spawn +License: MIT +By: André Cruz +Repository: git@github.com:moxystudio/node-cross-spawn.git + +> The MIT License (MIT) +> +> Copyright (c) 2018 Made With MOXY Lda +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. + +--------------------------------------- + +## isexe +License: ISC +By: Isaac Z. Schlueter +Repository: git+https://github.com/isaacs/isexe.git + +> The ISC License +> +> Copyright (c) Isaac Z. Schlueter and Contributors +> +> Permission to use, copy, modify, and/or distribute this software for any +> purpose with or without fee is hereby granted, provided that the above +> copyright notice and this permission notice appear in all copies. +> +> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +> ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +> IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +--------------------------------------- + +## kleur +License: MIT +By: Luke Edwards +Repository: lukeed/kleur + +> The MIT License (MIT) +> +> Copyright (c) Luke Edwards (lukeed.com) +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. + +--------------------------------------- + +## kolorist +License: MIT +By: Marvin Hagemeister +Repository: https://github.com/marvinhagemeister/kolorist.git + +> The MIT License (MIT) +> +> Copyright (c) 2020-present Marvin Hagemeister +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +--------------------------------------- + +## minimist +License: MIT +By: James Halliday +Repository: git://github.com/substack/minimist.git + +> This software is released under the MIT license: +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of +> this software and associated documentation files (the "Software"), to deal in +> the Software without restriction, including without limitation the rights to +> use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +> the Software, and to permit persons to whom the Software is furnished to do so, +> subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +> FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +> COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +> IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +> CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + +## path-key +License: MIT +By: Sindre Sorhus +Repository: sindresorhus/path-key + +> MIT License +> +> Copyright (c) Sindre Sorhus (sindresorhus.com) +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + +## prompts +License: MIT +By: Terkel Gjervig +Repository: terkelg/prompts + +> MIT License +> +> Copyright (c) 2018 Terkel Gjervig Nielsen +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +--------------------------------------- + +## shebang-command +License: MIT +By: Kevin Mårtensson +Repository: kevva/shebang-command + +> MIT License +> +> Copyright (c) Kevin Mårtensson (github.com/kevva) +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + +## shebang-regex +License: MIT +By: Sindre Sorhus +Repository: sindresorhus/shebang-regex + +> MIT License +> +> Copyright (c) Sindre Sorhus (sindresorhus.com) +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + +## sisteransi +License: MIT +By: Terkel Gjervig +Repository: https://github.com/terkelg/sisteransi + +> MIT License +> +> Copyright (c) 2018 Terkel Gjervig Nielsen +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +--------------------------------------- + +## which +License: ISC +By: Isaac Z. Schlueter +Repository: git://github.com/isaacs/node-which.git + +> The ISC License +> +> Copyright (c) Isaac Z. Schlueter and Contributors +> +> Permission to use, copy, modify, and/or distribute this software for any +> purpose with or without fee is hereby granted, provided that the above +> copyright notice and this permission notice appear in all copies. +> +> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +> ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +> IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/packages/create-vite/build.config.ts b/packages/create-vite/build.config.ts index ce0e9ef32548f0..8128526c6e3eec 100644 --- a/packages/create-vite/build.config.ts +++ b/packages/create-vite/build.config.ts @@ -1,11 +1,31 @@ +import path from 'node:path' +import url from 'node:url' import { defineBuildConfig } from 'unbuild' +import licensePlugin from '../../scripts/rollupLicensePlugin.mjs' + +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)) export default defineBuildConfig({ entries: ['src/index'], clean: true, rollup: { + inlineDependencies: true, esbuild: { minify: true } + }, + hooks: { + 'rollup:options'(ctx, options) { + if (!options.plugins) { + options.plugins = [] + } + options.plugins.push( + licensePlugin( + path.resolve(__dirname, './LICENSE'), + 'create-vite license', + 'create-vite' + ) + ) + } } }) diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index 1f8487a56584a8..76c33bcd95e75f 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -31,7 +31,7 @@ "url": "https://github.com/vitejs/vite/issues" }, "homepage": "https://github.com/vitejs/vite/tree/main/packages/create-vite#readme", - "dependencies": { + "devDependencies": { "cross-spawn": "^7.0.3", "kolorist": "^1.5.1", "minimist": "^1.2.6", diff --git a/packages/vite/rollup.config.ts b/packages/vite/rollup.config.ts index 0352654f2316ca..c333e66577f8d5 100644 --- a/packages/vite/rollup.config.ts +++ b/packages/vite/rollup.config.ts @@ -115,7 +115,12 @@ function createNodePlugins( ignore: ['bufferutil', 'utf-8-validate'] }), json(), - isProduction && licensePlugin(), + isProduction && + licensePlugin( + path.resolve(__dirname, 'LICENSE.md'), + 'Vite core license', + 'Vite' + ), cjsPatchPlugin() ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 72754c2cf360fe..e9789e8b3bd26f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,7 +128,7 @@ importers: kolorist: ^1.5.1 minimist: ^1.2.6 prompts: ^2.4.2 - dependencies: + devDependencies: cross-spawn: 7.0.3 kolorist: 1.5.1 minimist: 1.2.6 @@ -3990,6 +3990,7 @@ packages: path-key: 3.1.1 shebang-command: 2.0.0 which: 2.0.2 + dev: true /crosspath/0.0.8: resolution: {integrity: sha512-IKlS3MpP0fhJ50M6ltyLO7Q4NzwfhafpmolMH0EDKyyaY81HutF2mH4hLpCdm3fKZ/TSTW5qPIdTy62YnefEyQ==} @@ -6124,6 +6125,7 @@ packages: /isexe/2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + dev: true /jiti/1.14.0: resolution: {integrity: sha512-4IwstlaKQc9vCTC+qUXLM1hajy2ImiL9KnLvVYiaHOtS/v3wRjhLlGl121AmgDgx/O43uKmxownJghS5XMya2A==} @@ -6235,6 +6237,7 @@ packages: /kleur/3.0.3: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} + dev: true /kleur/4.1.4: resolution: {integrity: sha512-8QADVssbrFjivHWQU7KkMgptGTl6WAcSdlbBPY4uNF+mWr6DGcKrvY2w4FQJoXch7+fKMjj0dRrL75vk3k23OA==} @@ -6243,7 +6246,7 @@ packages: /kolorist/1.5.1: resolution: {integrity: sha512-lxpCM3HTvquGxKGzHeknB/sUjuVoUElLlfYnXZT73K8geR9jQbroGlSCFBax9/0mpGoD3kzcMLnOlGQPJJNyqQ==} - dev: false + dev: true /launch-editor-middleware/2.6.0: resolution: {integrity: sha512-K2yxgljj5TdCeRN1lBtO3/J26+AIDDDw+04y6VAiZbWcTdBwsYN6RrZBnW5DN/QiSIdKNjKdATLUUluWWFYTIA==} @@ -7125,6 +7128,7 @@ packages: /path-key/3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} + dev: true /path-key/4.0.0: resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==} @@ -7455,6 +7459,7 @@ packages: dependencies: kleur: 3.0.3 sisteransi: 1.0.5 + dev: true /prop-types/15.8.1: resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==} @@ -8065,6 +8070,7 @@ packages: engines: {node: '>=8'} dependencies: shebang-regex: 3.0.0 + dev: true /shebang-regex/1.0.0: resolution: {integrity: sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=} @@ -8074,6 +8080,7 @@ packages: /shebang-regex/3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} + dev: true /shell-exec/1.0.2: resolution: {integrity: sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg==} @@ -8119,6 +8126,7 @@ packages: /sisteransi/1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + dev: true /slash/3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} @@ -9083,6 +9091,7 @@ packages: hasBin: true dependencies: isexe: 2.0.0 + dev: true /wide-align/1.1.5: resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==} diff --git a/scripts/rollupLicensePlugin.mjs b/scripts/rollupLicensePlugin.mjs index a6dddf4baca45c..f96719e19bf9a6 100644 --- a/scripts/rollupLicensePlugin.mjs +++ b/scripts/rollupLicensePlugin.mjs @@ -7,7 +7,12 @@ import colors from 'picocolors' import fg from 'fast-glob' import { sync as resolve } from 'resolve' -function licensePlugin() { +/** + * @param {string} licenseFilePath + * @param {string} licenseTitle + * @param {string} packageName + */ +function licensePlugin(licenseFilePath, licenseTitle, packageName) { return license({ thirdParty(dependencies) { // https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js @@ -97,17 +102,17 @@ function licensePlugin() { ) .join('\n---------------------------------------\n\n') const licenseText = - `# Vite core license\n` + - `Vite is released under the MIT license:\n\n` + + `# ${licenseTitle}\n` + + `${packageName} is released under the MIT license:\n\n` + coreLicense + `\n# Licenses of bundled dependencies\n` + - `The published Vite artifact additionally contains code with the following licenses:\n` + + `The published ${packageName} artifact additionally contains code with the following licenses:\n` + `${sortLicenses(licenses).join(', ')}\n\n` + `# Bundled dependencies:\n` + dependencyLicenseTexts - const existingLicenseText = fs.readFileSync('LICENSE.md', 'utf8') + const existingLicenseText = fs.readFileSync(licenseFilePath, 'utf8') if (existingLicenseText !== licenseText) { - fs.writeFileSync('LICENSE.md', licenseText) + fs.writeFileSync(licenseFilePath, licenseText) console.warn( colors.yellow( '\nLICENSE.md updated. You should commit the updated file.\n' From fb49a3ba1116ad0ff5caff3b9f1b200017addf19 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 11 Jul 2022 12:17:10 +0900 Subject: [PATCH 6/6] perf(create-vite): exclude transpiled `prompts` code --- packages/create-vite/build.config.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/create-vite/build.config.ts b/packages/create-vite/build.config.ts index 8128526c6e3eec..2c39d19d427de6 100644 --- a/packages/create-vite/build.config.ts +++ b/packages/create-vite/build.config.ts @@ -14,6 +14,10 @@ export default defineBuildConfig({ minify: true } }, + alias: { + // we can always use non-transpiled code since we support 14.18.0+ + prompts: 'prompts/lib/index.js' + }, hooks: { 'rollup:options'(ctx, options) { if (!options.plugins) {