chore: cleanup tweaks that would affect JS; rolled back packages folder to @pikax output

This commit is contained in:
David Welch 2022-05-04 15:16:17 -06:00
parent 40dccfedd1
commit e2f1ce06cf
20 changed files with 24166 additions and 24158 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,113 +1,113 @@
'use strict';
const isJS = (file) => /\.js(\?[^.]+)?$/.test(file);
const isJS = (file) => /\.js(\?[^.]+)?$/.test(file);
const isCSS = (file) => /\.css(\?[^.]+)?$/.test(file);
const { red, yellow } = require('chalk');
const webpack = require('webpack');
const prefix = `[vue-server-renderer-webpack-plugin]`;
exports.warn = msg => console.error(red(`${prefix} ${msg}\n`));
exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`));
const isWebpack5 = !!(webpack.version && webpack.version[0] > 4);
const onEmit = (compiler, name, stageName, hook) => {
if (isWebpack5) {
// Webpack >= 5.0.0
compiler.hooks.compilation.tap(name, compilation => {
if (compilation.compiler !== compiler) {
// Ignore child compilers
return;
}
const stage = webpack.Compilation[stageName];
compilation.hooks.processAssets.tapAsync({ name, stage }, (assets, cb) => {
hook(compilation, cb);
});
});
}
else if (compiler.hooks) {
// Webpack >= 4.0.0
compiler.hooks.emit.tapAsync(name, hook);
}
else {
// Webpack < 4.0.0
compiler.plugin('emit', hook);
}
};
const stripModuleIdHash = id => {
if (isWebpack5) {
// Webpack >= 5.0.0
return id.replace(/\|\w+$/, '');
}
// Webpack < 5.0.0
return id.replace(/\s\w+$/, '');
};
const getAssetName = asset => {
if (typeof asset === 'string') {
return asset;
}
return asset.name;
const { red, yellow } = require('chalk');
const webpack = require('webpack');
const prefix = `[vue-server-renderer-webpack-plugin]`;
exports.warn = msg => console.error(red(`${prefix} ${msg}\n`));
exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`));
const isWebpack5 = !!(webpack.version && webpack.version[0] > 4);
const onEmit = (compiler, name, stageName, hook) => {
if (isWebpack5) {
// Webpack >= 5.0.0
compiler.hooks.compilation.tap(name, compilation => {
if (compilation.compiler !== compiler) {
// Ignore child compilers
return;
}
const stage = webpack.Compilation[stageName];
compilation.hooks.processAssets.tapAsync({ name, stage }, (assets, cb) => {
hook(compilation, cb);
});
});
}
else if (compiler.hooks) {
// Webpack >= 4.0.0
compiler.hooks.emit.tapAsync(name, hook);
}
else {
// Webpack < 4.0.0
compiler.plugin('emit', hook);
}
};
const stripModuleIdHash = id => {
if (isWebpack5) {
// Webpack >= 5.0.0
return id.replace(/\|\w+$/, '');
}
// Webpack < 5.0.0
return id.replace(/\s\w+$/, '');
};
const getAssetName = asset => {
if (typeof asset === 'string') {
return asset;
}
return asset.name;
};
const hash = require("hash-sum");
const uniq = require("lodash.uniq");
class VueSSRClientPlugin {
constructor(options = {}) {
//@ts-expect-error no type on options
this.options = Object.assign({
filename: "vue-ssr-client-manifest.json",
}, options);
}
apply(compiler) {
const stage = "PROCESS_ASSETS_STAGE_ADDITIONAL";
onEmit(compiler, "vue-client-plugin", stage, (compilation, cb) => {
const stats = compilation.getStats().toJson();
const allFiles = uniq(stats.assets.map((a) => a.name));
const initialFiles = uniq(Object.keys(stats.entrypoints)
.map((name) => stats.entrypoints[name].assets)
.reduce((assets, all) => all.concat(assets), [])
.map(getAssetName)
.filter((file) => isJS(file) || isCSS(file)));
const asyncFiles = allFiles
.filter((file) => isJS(file) || isCSS(file))
.filter((file) => initialFiles.indexOf(file) < 0);
const manifest = {
publicPath: stats.publicPath,
all: allFiles,
initial: initialFiles,
async: asyncFiles,
modules: {
/* [identifier: string]: Array<index: number> */
},
};
const assetModules = stats.modules.filter((m) => m.assets.length);
const fileToIndex = (asset) => manifest.all.indexOf(getAssetName(asset));
stats.modules.forEach((m) => {
// ignore modules duplicated in multiple chunks
if (m.chunks.length === 1) {
const cid = m.chunks[0];
const chunk = stats.chunks.find((c) => c.id === cid);
if (!chunk || !chunk.files) {
return;
}
const id = stripModuleIdHash(m.identifier);
const files = (manifest.modules[hash(id)] =
chunk.files.map(fileToIndex));
// find all asset modules associated with the same chunk
assetModules.forEach((m) => {
if (m.chunks.some((id) => id === cid)) {
files.push.apply(files, m.assets.map(fileToIndex));
}
});
}
});
const json = JSON.stringify(manifest, null, 2);
//@ts-expect-error no type on options
compilation.assets[this.options.filename] = {
source: () => json,
size: () => json.length,
};
cb();
});
}
const hash = require("hash-sum");
const uniq = require("lodash.uniq");
class VueSSRClientPlugin {
constructor(options = {}) {
//@ts-expect-error no type on options
this.options = Object.assign({
filename: "vue-ssr-client-manifest.json",
}, options);
}
apply(compiler) {
const stage = "PROCESS_ASSETS_STAGE_ADDITIONAL";
onEmit(compiler, "vue-client-plugin", stage, (compilation, cb) => {
const stats = compilation.getStats().toJson();
const allFiles = uniq(stats.assets.map((a) => a.name));
const initialFiles = uniq(Object.keys(stats.entrypoints)
.map((name) => stats.entrypoints[name].assets)
.reduce((assets, all) => all.concat(assets), [])
.map(getAssetName)
.filter((file) => isJS(file) || isCSS(file)));
const asyncFiles = allFiles
.filter((file) => isJS(file) || isCSS(file))
.filter((file) => initialFiles.indexOf(file) < 0);
const manifest = {
publicPath: stats.publicPath,
all: allFiles,
initial: initialFiles,
async: asyncFiles,
modules: {
/* [identifier: string]: Array<index: number> */
},
};
const assetModules = stats.modules.filter((m) => m.assets.length);
const fileToIndex = (asset) => manifest.all.indexOf(getAssetName(asset));
stats.modules.forEach((m) => {
// ignore modules duplicated in multiple chunks
if (m.chunks.length === 1) {
const cid = m.chunks[0];
const chunk = stats.chunks.find((c) => c.id === cid);
if (!chunk || !chunk.files) {
return;
}
const id = stripModuleIdHash(m.identifier);
const files = (manifest.modules[hash(id)] =
chunk.files.map(fileToIndex));
// find all asset modules associated with the same chunk
assetModules.forEach((m) => {
if (m.chunks.some((id) => id === cid)) {
files.push.apply(files, m.assets.map(fileToIndex));
}
});
}
});
const json = JSON.stringify(manifest, null, 2);
//@ts-expect-error no type on options
compilation.assets[this.options.filename] = {
source: () => json,
size: () => json.length,
};
cb();
});
}
}
module.exports = VueSSRClientPlugin;

View File

@ -2,117 +2,117 @@
const isJS = (file) => /\.js(\?[^.]+)?$/.test(file);
const { red, yellow } = require('chalk');
const webpack = require('webpack');
const prefix = `[vue-server-renderer-webpack-plugin]`;
const warn = exports.warn = msg => console.error(red(`${prefix} ${msg}\n`));
const tip = exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`));
const isWebpack5 = !!(webpack.version && webpack.version[0] > 4);
const validate = compiler => {
if (compiler.options.target !== 'node') {
warn('webpack config `target` should be "node".');
}
if (compiler.options.output) {
if (compiler.options.output.library) {
// Webpack >= 5.0.0
if (compiler.options.output.library.type !== 'commonjs2') {
warn('webpack config `output.library.type` should be "commonjs2".');
}
}
else if (compiler.options.output.libraryTarget !== 'commonjs2') {
// Webpack < 5.0.0
warn('webpack config `output.libraryTarget` should be "commonjs2".');
}
}
if (!compiler.options.externals) {
tip('It is recommended to externalize dependencies in the server build for ' +
'better build performance.');
}
};
const onEmit = (compiler, name, stageName, hook) => {
if (isWebpack5) {
// Webpack >= 5.0.0
compiler.hooks.compilation.tap(name, compilation => {
if (compilation.compiler !== compiler) {
// Ignore child compilers
return;
}
const stage = webpack.Compilation[stageName];
compilation.hooks.processAssets.tapAsync({ name, stage }, (assets, cb) => {
hook(compilation, cb);
});
});
}
else if (compiler.hooks) {
// Webpack >= 4.0.0
compiler.hooks.emit.tapAsync(name, hook);
}
else {
// Webpack < 4.0.0
compiler.plugin('emit', hook);
}
};
const getAssetName = asset => {
if (typeof asset === 'string') {
return asset;
}
return asset.name;
const { red, yellow } = require('chalk');
const webpack = require('webpack');
const prefix = `[vue-server-renderer-webpack-plugin]`;
const warn = exports.warn = msg => console.error(red(`${prefix} ${msg}\n`));
const tip = exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`));
const isWebpack5 = !!(webpack.version && webpack.version[0] > 4);
const validate = compiler => {
if (compiler.options.target !== 'node') {
warn('webpack config `target` should be "node".');
}
if (compiler.options.output) {
if (compiler.options.output.library) {
// Webpack >= 5.0.0
if (compiler.options.output.library.type !== 'commonjs2') {
warn('webpack config `output.library.type` should be "commonjs2".');
}
}
else if (compiler.options.output.libraryTarget !== 'commonjs2') {
// Webpack < 5.0.0
warn('webpack config `output.libraryTarget` should be "commonjs2".');
}
}
if (!compiler.options.externals) {
tip('It is recommended to externalize dependencies in the server build for ' +
'better build performance.');
}
};
const onEmit = (compiler, name, stageName, hook) => {
if (isWebpack5) {
// Webpack >= 5.0.0
compiler.hooks.compilation.tap(name, compilation => {
if (compilation.compiler !== compiler) {
// Ignore child compilers
return;
}
const stage = webpack.Compilation[stageName];
compilation.hooks.processAssets.tapAsync({ name, stage }, (assets, cb) => {
hook(compilation, cb);
});
});
}
else if (compiler.hooks) {
// Webpack >= 4.0.0
compiler.hooks.emit.tapAsync(name, hook);
}
else {
// Webpack < 4.0.0
compiler.plugin('emit', hook);
}
};
const getAssetName = asset => {
if (typeof asset === 'string') {
return asset;
}
return asset.name;
};
class VueSSRServerPlugin {
constructor(options = {}) {
//@ts-expect-error
this.options = Object.assign({
filename: 'vue-ssr-server-bundle.json',
}, options);
}
apply(compiler) {
validate(compiler);
const stage = 'PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER';
onEmit(compiler, 'vue-server-plugin', stage, (compilation, cb) => {
const stats = compilation.getStats().toJson();
const entryName = Object.keys(stats.entrypoints)[0];
const entryInfo = stats.entrypoints[entryName];
if (!entryInfo) {
// #5553
return cb();
}
const entryAssets = entryInfo.assets
.map(getAssetName)
.filter(isJS);
if (entryAssets.length > 1) {
throw new Error(`Server-side bundle should have one single entry file. ` +
`Avoid using CommonsChunkPlugin in the server config.`);
}
const entry = entryAssets[0];
if (!entry || typeof entry !== 'string') {
throw new Error(`Entry "${entryName}" not found. Did you specify the correct entry option?`);
}
const bundle = {
entry,
files: {},
maps: {},
};
Object.keys(compilation.assets).forEach(name => {
if (isJS(name)) {
bundle.files[name] = compilation.assets[name].source();
}
else if (name.match(/\.js\.map$/)) {
bundle.maps[name.replace(/\.map$/, '')] = JSON.parse(compilation.assets[name].source());
}
// do not emit anything else for server
delete compilation.assets[name];
});
const json = JSON.stringify(bundle, null, 2);
//@ts-expect-error
const filename = this.options.filename;
compilation.assets[filename] = {
source: () => json,
size: () => json.length,
};
cb();
});
}
class VueSSRServerPlugin {
constructor(options = {}) {
//@ts-expect-error
this.options = Object.assign({
filename: 'vue-ssr-server-bundle.json',
}, options);
}
apply(compiler) {
validate(compiler);
const stage = 'PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER';
onEmit(compiler, 'vue-server-plugin', stage, (compilation, cb) => {
const stats = compilation.getStats().toJson();
const entryName = Object.keys(stats.entrypoints)[0];
const entryInfo = stats.entrypoints[entryName];
if (!entryInfo) {
// #5553
return cb();
}
const entryAssets = entryInfo.assets
.map(getAssetName)
.filter(isJS);
if (entryAssets.length > 1) {
throw new Error(`Server-side bundle should have one single entry file. ` +
`Avoid using CommonsChunkPlugin in the server config.`);
}
const entry = entryAssets[0];
if (!entry || typeof entry !== 'string') {
throw new Error(`Entry "${entryName}" not found. Did you specify the correct entry option?`);
}
const bundle = {
entry,
files: {},
maps: {},
};
Object.keys(compilation.assets).forEach(name => {
if (isJS(name)) {
bundle.files[name] = compilation.assets[name].source();
}
else if (name.match(/\.js\.map$/)) {
bundle.maps[name.replace(/\.map$/, '')] = JSON.parse(compilation.assets[name].source());
}
// do not emit anything else for server
delete compilation.assets[name];
});
const json = JSON.stringify(bundle, null, 2);
//@ts-expect-error
const filename = this.options.filename;
compilation.assets[filename] = {
source: () => json,
size: () => json.length,
};
cb();
});
}
}
module.exports = VueSSRServerPlugin;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,3 @@
/* globals */
declare const stats: any
declare const valueToPoint: Function
@ -45,7 +43,7 @@ module.exports = {
const point = valueToPoint(stat.value, i, 6)
return point.x + ',' + point.y
}).join(' ')
return document.querySelector('polygon').attributes[0].value === points
return document.querySelector('polygon')!.attributes[0].value === points
})
.end()
}

View File

@ -52,10 +52,10 @@ beforeEach(() => {
spyOn(console, 'error')
jasmine.addMatchers({
toHaveBeenWarned: () =>
// @ts-ignore
// @ts-expect-error
createCompareFn(console.error),
toHaveBeenTipped: () =>
// @ts-ignore
// @ts-expect-error
createCompareFn(console.warn)
})
})

View File

@ -1,4 +1,4 @@
global.triggerEvent = function triggerEvent (target, event, process) {
window.triggerEvent = function triggerEvent (target, event, process) {
const e = document.createEvent('HTMLEvents')
e.initEvent(event, true, true)
if (event === 'click') {

View File

@ -12,7 +12,7 @@ import Vue from 'vue'
// // more assertions...
// })
// .then(done)
// @ts-expect-error
window.waitForUpdate = initialCb => {
let end
const queue = initialCb ? [initialCb] : []
@ -30,7 +30,7 @@ window.waitForUpdate = initialCb => {
done.fail(e)
}
}
if (!hasError && !job?.wait) {
if (!hasError && !job!.wait) {
if (queue.length) {
Vue.nextTick(shift)
}
@ -41,7 +41,7 @@ window.waitForUpdate = initialCb => {
}
Vue.nextTick(() => {
if (!queue.length || (!end && !queue[queue.length - 1]?.fail)) {
if (!queue.length || (!end && !queue[queue.length - 1]!.fail)) {
throw new Error('waitForUpdate chain is missing .then(done)')
}
shift()

View File

@ -3,9 +3,6 @@ import webpack from 'webpack'
import MemoryFS from 'memory-fs'
export function compileWithWebpack (file, extraConfig, cb) {
if( process.env.FOOBAR !== 'blah') {
throw new Error('die')
}
const config = Object.assign({
mode: 'development',
entry: path.resolve(__dirname, 'fixtures', file),

View File

@ -3,7 +3,8 @@ import { formatComponentName, warn } from 'core/util/debug'
describe('Debug utilities', () => {
it('properly format component names', () => {
const vm = new Vue('div')
// @ts-expect-error
const vm = new Vue()
expect(formatComponentName(vm)).toBe('<Root>')
vm.$root = null
@ -83,7 +84,8 @@ found in
describe('warn', () => {
const msg = 'message'
const vm = new Vue('div')
// @ts-expect-error
const vm = new Vue()
it('calls warnHandler if warnHandler is set', () => {
Vue.config.warnHandler = jasmine.createSpy()

View File

@ -170,7 +170,8 @@ describe('Error handling', () => {
Vue.nextTick(() => {
expect(spy).toHaveBeenCalledWith(err1, undefined, 'nextTick')
const vm = new Vue('div')
// @ts-expect-error
const vm = new Vue()
vm.$nextTick(() => { throw err2 })
Vue.nextTick(() => {
// should be called with correct instance info

View File

@ -2,11 +2,13 @@ import Vue from 'vue'
describe('Initialization', () => {
it('without new', () => {
try { Vue('div') } catch (e) {}
// @ts-expect-error
try { Vue() } catch (e) {}
expect('Vue is a constructor and should be called with the `new` keyword').toHaveBeenWarned()
})
it('with new', () => {
expect(new Vue('div') instanceof Vue).toBe(true)
// @ts-expect-error
expect(new Vue() instanceof Vue).toBe(true)
})
})

View File

@ -3,7 +3,8 @@ import Vue from 'vue'
describe('Instance methods events', () => {
let vm, spy
beforeEach(() => {
vm = new Vue('div')
// @ts-expect-error
const vm = new Vue()
spy = jasmine.createSpy('emitter')
})

View File

@ -161,7 +161,8 @@ describe('Instance properties', () => {
})
it('warn mutating $attrs', () => {
const vm = new Vue('div')
// @ts-expect-error
const vm = new Vue()
vm.$attrs = {}
expect(`$attrs is readonly`).toHaveBeenWarned()
})
@ -196,7 +197,8 @@ describe('Instance properties', () => {
})
it('warn mutating $listeners', () => {
const vm = new Vue('div')
// @ts-expect-error
const vm = new Vue()
vm.$listeners = {}
expect(`$listeners is readonly`).toHaveBeenWarned()
})

View File

@ -78,7 +78,8 @@ describe('Options lifecycle hooks', () => {
// #3898
it('should call for manually mounted instance with parent', () => {
const parent = new Vue('div')
// @ts-expect-error
const vm = new Vue()
expect(spy).not.toHaveBeenCalled()
new Vue({
parent,

View File

@ -33,7 +33,8 @@ describe('Options render', () => {
})
it('should warn non `render` option and non `template` option', () => {
new Vue('div').$mount()
// @ts-expect-error
new Vue().$mount()
expect('Failed to mount component: template or render function not defined.').toHaveBeenWarned()
})
})

View File

@ -23,7 +23,7 @@ if (!isIE9) {
// should not apply transition on initial render by default
expect(vm.$el.innerHTML).toBe('<div class="test">foo</div>')
vm.ok = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.children[0].className).toBe('test v-leave v-leave-active')
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.children[0].className).toBe('test v-leave-active v-leave-to')

View File

@ -14,7 +14,8 @@ describe('Observer', () => {
const ob1 = observe(1)
expect(ob1).toBeUndefined()
// avoid vue instance
const ob2 = observe(new Vue('div'))
// @ts-expect-error
const ob2 = observe(new Vue())
expect(ob2).toBeUndefined()
// avoid frozen objects
const ob3 = observe(Object.freeze({}))