diff --git a/jest.config.js b/jest.config.js index e76e0840..443ebca1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -46,7 +46,8 @@ module.exports = { moduleNameMapper: { '@vue/compat': '/packages/vue-compat/src', '^@vue/(.*?)$': '/packages/$1/src', - vue: '/packages/vue/src' + vue: '/packages/vue/src', + '@vue/consolidate': '@vue/consolidate' }, rootDir: __dirname, testMatch: ['/packages/**/__tests__/**/*spec.[jt]s?(x)'], diff --git a/package.json b/package.json index a6dea40f..5fec617e 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,9 @@ "serve": "^12.0.0", "ts-jest": "^27.0.5", "typescript": "^4.2.2", - "yorkie": "^2.0.0" + "yorkie": "^2.0.0", + "lodash": "^4.17.15", + "marked": "^0.7.0", + "todomvc-app-css": "^2.3.0" } } diff --git a/packages/compiler-core/package.json b/packages/compiler-core/package.json index a042c8a2..c8aaddd1 100644 --- a/packages/compiler-core/package.json +++ b/packages/compiler-core/package.json @@ -34,8 +34,10 @@ "dependencies": { "@vue/shared": "3.2.12", "@babel/parser": "^7.15.0", - "@babel/types": "^7.15.0", "estree-walker": "^2.0.2", "source-map": "^0.6.1" + }, + "devDependencies": { + "@babel/types": "^7.15.0" } } diff --git a/packages/compiler-sfc/package.json b/packages/compiler-sfc/package.json index 6986db5a..c3f7cc8e 100644 --- a/packages/compiler-sfc/package.json +++ b/packages/compiler-sfc/package.json @@ -33,28 +33,27 @@ "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-sfc#readme", "dependencies": { "@babel/parser": "^7.15.0", - "@types/estree": "^0.0.48", "@vue/compiler-core": "3.2.12", "@vue/compiler-dom": "3.2.12", "@vue/compiler-ssr": "3.2.12", "@vue/ref-transform": "3.2.12", "@vue/shared": "3.2.12", - "consolidate": "^0.16.0", "estree-walker": "^2.0.2", - "hash-sum": "^2.0.0", - "lru-cache": "^5.1.1", "magic-string": "^0.25.7", - "merge-source-map": "^1.1.0", - "postcss": "^8.1.10", - "postcss-modules": "^4.0.0", - "postcss-selector-parser": "^6.0.4", - "source-map": "^0.6.1" + "source-map": "^0.6.1", + "postcss": "^8.1.10" }, "devDependencies": { + "@types/estree": "^0.0.48", "@babel/types": "^7.15.0", - "@types/consolidate": "^0.14.0", "@types/lru-cache": "^5.1.0", "pug": "^3.0.1", - "sass": "^1.26.9" + "sass": "^1.26.9", + "@vue/consolidate": "^0.17.2", + "hash-sum": "^2.0.0", + "lru-cache": "^5.1.1", + "merge-source-map": "^1.1.0", + "postcss-modules": "^4.0.0", + "postcss-selector-parser": "^6.0.4" } } diff --git a/packages/compiler-sfc/src/cache.ts b/packages/compiler-sfc/src/cache.ts index 42d5b63f..510dfee3 100644 --- a/packages/compiler-sfc/src/cache.ts +++ b/packages/compiler-sfc/src/cache.ts @@ -1,5 +1,7 @@ +import LRU from 'lru-cache' + export function createCache(size = 500) { return __GLOBAL__ || __ESM_BROWSER__ ? new Map() - : (new (require('lru-cache'))(size) as Map) + : (new LRU(size) as any as Map) } diff --git a/packages/compiler-sfc/src/compileStyle.ts b/packages/compiler-sfc/src/compileStyle.ts index ce59bd56..8e02eaf6 100644 --- a/packages/compiler-sfc/src/compileStyle.ts +++ b/packages/compiler-sfc/src/compileStyle.ts @@ -15,6 +15,7 @@ import { } from './stylePreprocessors' import { RawSourceMap } from 'source-map' import { cssVarsPlugin } from './cssVars' +import postcssModules from 'postcss-modules' export interface SFCStyleCompileOptions { source: string @@ -47,7 +48,7 @@ export interface CSSModulesOptions { hashPrefix?: string localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly' exportGlobals?: boolean - globalModulePaths?: string[] + globalModulePaths?: RegExp[] } export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions { @@ -131,7 +132,7 @@ export function doCompileStyle( ) } plugins.push( - require('postcss-modules')({ + postcssModules({ ...modulesOptions, getJSON: (_cssFileName: string, json: Record) => { cssModules = json diff --git a/packages/compiler-sfc/src/compileTemplate.ts b/packages/compiler-sfc/src/compileTemplate.ts index 6f44616d..4ddd0059 100644 --- a/packages/compiler-sfc/src/compileTemplate.ts +++ b/packages/compiler-sfc/src/compileTemplate.ts @@ -21,7 +21,7 @@ import { import { generateCodeFrame, isObject } from '@vue/shared' import * as CompilerDOM from '@vue/compiler-dom' import * as CompilerSSR from '@vue/compiler-ssr' -import consolidate from 'consolidate' +import consolidate from '@vue/consolidate' import { warnOnce } from './warn' import { genCssVarsFromList } from './cssVars' @@ -121,7 +121,7 @@ export function compileTemplate( ? preprocessCustomRequire(preprocessLang) : __ESM_BROWSER__ ? undefined - : require('consolidate')[preprocessLang as keyof typeof consolidate] + : consolidate[preprocessLang as keyof typeof consolidate] : false if (preprocessor) { try { diff --git a/packages/vue/compiler-sfc/index.d.ts b/packages/vue/compiler-sfc/index.d.ts new file mode 100644 index 00000000..3c30abc8 --- /dev/null +++ b/packages/vue/compiler-sfc/index.d.ts @@ -0,0 +1 @@ +export * from '@vue/compiler-sfc' diff --git a/packages/vue/compiler-sfc/index.js b/packages/vue/compiler-sfc/index.js new file mode 100644 index 00000000..774f9da2 --- /dev/null +++ b/packages/vue/compiler-sfc/index.js @@ -0,0 +1 @@ +module.exports = require('@vue/compiler-sfc') diff --git a/packages/vue/compiler-sfc/index.mjs b/packages/vue/compiler-sfc/index.mjs new file mode 100644 index 00000000..8df9a989 --- /dev/null +++ b/packages/vue/compiler-sfc/index.mjs @@ -0,0 +1 @@ +export * from '@vue/compiler-sfc' \ No newline at end of file diff --git a/packages/vue/compiler-sfc/package.json b/packages/vue/compiler-sfc/package.json new file mode 100644 index 00000000..1b15fb84 --- /dev/null +++ b/packages/vue/compiler-sfc/package.json @@ -0,0 +1,5 @@ +{ + "main": "index.js", + "module": "index.mjs", + "types": "index.d.ts" +} \ No newline at end of file diff --git a/packages/vue/package.json b/packages/vue/package.json index f6b4a01e..f4798171 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -10,6 +10,8 @@ "files": [ "index.js", "dist", + "compiler-sfc", + "server-renderer", "ref-macros.d.ts" ], "buildOptions": { @@ -40,11 +42,8 @@ "dependencies": { "@vue/shared": "3.2.12", "@vue/compiler-dom": "3.2.12", - "@vue/runtime-dom": "3.2.12" - }, - "devDependencies": { - "lodash": "^4.17.15", - "marked": "^0.7.0", - "todomvc-app-css": "^2.3.0" + "@vue/runtime-dom": "3.2.12", + "@vue/compiler-sfc": "3.2.12", + "@vue/server-renderer": "3.2.12" } } diff --git a/packages/vue/server-renderer/index.d.ts b/packages/vue/server-renderer/index.d.ts new file mode 100644 index 00000000..ac614729 --- /dev/null +++ b/packages/vue/server-renderer/index.d.ts @@ -0,0 +1 @@ +export * from '@vue/server-renderer' diff --git a/packages/vue/server-renderer/index.js b/packages/vue/server-renderer/index.js new file mode 100644 index 00000000..1761ed91 --- /dev/null +++ b/packages/vue/server-renderer/index.js @@ -0,0 +1 @@ +module.exports = require('@vue/server-renderer') diff --git a/packages/vue/server-renderer/index.mjs b/packages/vue/server-renderer/index.mjs new file mode 100644 index 00000000..3e081c15 --- /dev/null +++ b/packages/vue/server-renderer/index.mjs @@ -0,0 +1 @@ +export * from '@vue/server-renderer' \ No newline at end of file diff --git a/packages/vue/server-renderer/package.json b/packages/vue/server-renderer/package.json new file mode 100644 index 00000000..1b15fb84 --- /dev/null +++ b/packages/vue/server-renderer/package.json @@ -0,0 +1,5 @@ +{ + "main": "index.js", + "module": "index.mjs", + "types": "index.d.ts" +} \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js index a8b6ab48..d1fc2602 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -36,7 +36,6 @@ const outputConfigs = { file: resolve(`dist/${name}.global.js`), format: `iife` }, - // runtime-only builds, for main "vue" package only 'esm-bundler-runtime': { file: resolve(`dist/${name}.runtime.esm-bundler.js`), @@ -140,7 +139,7 @@ function createConfig(format, output, plugins = []) { } } else { // Node / esm-bundler builds. - // externalize all deps unless it's the compat build. + // externalize all direct deps unless it's the compat build. external = [ ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {}), @@ -148,21 +147,35 @@ function createConfig(format, output, plugins = []) { ] } - // the browser builds of @vue/compiler-sfc requires postcss to be available - // as a global (e.g. http://wzrd.in/standalone/postcss) - output.globals = { - postcss: 'postcss' + // we are bundling forked consolidate.js in compiler-sfc which dynamically + // requires a ton of template engines which should be ignored. + let cjsIgnores = [] + if (pkg.name === '@vue/compiler-sfc') { + cjsIgnores = [ + ...Object.keys(require('@vue/consolidate/package.json').devDependencies), + 'vm', + 'crypto', + 'react-dom/server', + 'teacup/lib/express', + 'arc-templates/dist/es5', + 'then-pug', + 'then-jade' + ] } const nodePlugins = - packageOptions.enableNonBrowserBranches && format !== 'cjs' + (format === 'cjs' && Object.keys(pkg.devDependencies || {}).length) || + packageOptions.enableNonBrowserBranches ? [ // @ts-ignore require('@rollup/plugin-commonjs')({ - sourceMap: false + sourceMap: false, + ignore: cjsIgnores }), - // @ts-ignore - require('rollup-plugin-polyfill-node')(), + ...(format === 'cjs' + ? [] + : // @ts-ignore + [require('rollup-plugin-polyfill-node')()]), require('@rollup/plugin-node-resolve').nodeResolve() ] : [] diff --git a/yarn.lock b/yarn.lock index 5e2a3ec3..c4e33de8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -739,19 +739,6 @@ dependencies: "@babel/types" "^7.3.0" -"@types/bluebird@*": - version "3.5.36" - resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.36.tgz#00d9301d4dc35c2f6465a8aec634bb533674c652" - integrity sha512-HBNx4lhkxN7bx6P0++W8E289foSu8kO8GCk2unhuVggO+cE7rh9DhZUyPhUxNRG9m+5B5BTKxZQ5ZP92x/mx9Q== - -"@types/consolidate@^0.14.0": - version "0.14.1" - resolved "https://registry.yarnpkg.com/@types/consolidate/-/consolidate-0.14.1.tgz#78f01b1ed747d945dea9969581fcc1d0cb59bad8" - integrity sha512-p0QTiPgjYssVJEo8zJ1WPfvfCpSvIU9oLZ7WPKl4Nx5dvaRAGb7Mk0a14T6UOVhI5PXYL7CkM4+lS7VRrUePUQ== - dependencies: - "@types/bluebird" "*" - "@types/node" "*" - "@types/estree@*": version "0.0.50" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.50.tgz#1e0caa9364d3fccd2931c3ed96fdbeaa5d4cca83" @@ -928,6 +915,11 @@ resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-1.8.1.tgz#6cc2a8dfd04201e3c868c239091aaa89aa75f880" integrity sha512-gktQGZ7qfaDdVJhT86fWSkyhP+bdoA81f5S2TQOL5Sbe5q7B36XfLGq8Q0BpHoqhPSflAMe6WwM1IecP1sChRw== +"@vue/consolidate@^0.17.2": + version "0.17.2" + resolved "https://registry.yarnpkg.com/@vue/consolidate/-/consolidate-0.17.2.tgz#8a871a638ae94fd88660a235b7b0837538b92e35" + integrity sha512-OG4/GJDOJdERTBw7G/gXE1Xf0cbPEBGJ73sBe7pOeMR4A0x3JNjKuwcv7QjXSOsWiYtsqDDgaKFac9fj1Gv1fw== + "@vue/repl@^0.3.7": version "0.3.7" resolved "https://registry.yarnpkg.com/@vue/repl/-/repl-0.3.7.tgz#e5bd0f4a87ce1ce88bc03a09ec1bb5ccec779bce" @@ -1266,11 +1258,6 @@ bl@~0.8.1: dependencies: readable-stream "~1.0.26" -bluebird@^3.7.2: - version "3.7.2" - resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" - integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== - bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9: version "4.12.0" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" @@ -1732,13 +1719,6 @@ concat-stream@^1.4.4: readable-stream "^2.2.2" typedarray "^0.0.6" -consolidate@^0.16.0: - version "0.16.0" - resolved "https://registry.yarnpkg.com/consolidate/-/consolidate-0.16.0.tgz#a11864768930f2f19431660a65906668f5fbdc16" - integrity sha512-Nhl1wzCslqXYTJVDyJCu3ODohy9OfBMB5uD2BiBTzd7w+QY0lBzafkR8y8755yMYHAaMD4NuzbAw03/xzfw+eQ== - dependencies: - bluebird "^3.7.2" - constantinople@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/constantinople/-/constantinople-4.0.1.tgz#0def113fa0e4dc8de83331a5cf79c8b325213151"