first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

75
node_modules/zrender/build/.jshintrc generated vendored Normal file
View File

@ -0,0 +1,75 @@
{
"bitwise": false,
"camelcase": true,
"curly": true,
"eqeqeq": false,
"forin": false,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": false,
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"regexp": false,
"undef": true,
"unused": "vars",
"strict": false,
"trailing": false,
"maxparams": 20,
"maxdepth": 6,
"maxlen": 200,
"asi": false,
"boss": false,
"debug": false,
"eqnull": true,
"esversion": 6,
"evil": true,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": false,
"multistr": false,
"onecase": false,
"proto": false,
"regexdash": false,
"scripturl": false,
"smarttabs": false,
"shadow": true,
"sub": true,
"supernew": false,
"validthis": true,
"browser": true,
"couch": false,
"devel": true,
"dojo": false,
"jquery": true,
"mootools": false,
"node": false,
"nonstandard": false,
"prototypejs": false,
"rhino": false,
"wsh": false,
"nomen": false,
"onevar": false,
"passfail": false,
"white": false,
"varstmt": true,
"predef": [
"global",
"require",
"exports",
"module",
"__dirname"
]
}

13860
node_modules/zrender/build/amd2common.bundle.js generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,736 @@
/**
* Both used by zrender and echarts.
*/
const assert = require('assert');
const nodePath = require('path');
const basename = nodePath.basename;
const extname = nodePath.extname;
const babelTypes = require('@babel/types');
const babelTemplate = require('@babel/template');
const helperModuleTransforms = require('@babel/helper-module-transforms');
const isModule = helperModuleTransforms.isModule;
const isSideEffectImport = helperModuleTransforms.isSideEffectImport;
const ensureStatementsHoisted = helperModuleTransforms.ensureStatementsHoisted;
module.exports = function ({types, template}, options) {
return {
visitor: {
Program: {
exit(path) {
// For now this requires unambiguous rather that just sourceType
// because Babel currently parses all files as sourceType:module.
if (!isModule(path, true /* requireUnambiguous */)) {
return;
}
// Rename the bindings auto-injected into the scope so there is no
// risk of conflict between the bindings.
path.scope.rename('exports');
path.scope.rename('module');
path.scope.rename('require');
path.scope.rename('__filename');
path.scope.rename('__dirname');
const meta = rewriteModuleStatementsAndPrepare(path);
let headers = [];
let tails = [];
const checkExport = createExportChecker();
for (const [source, metadata] of meta.source) {
headers.push(...buildRequireStatements(types, source, metadata));
headers.push(...buildNamespaceInitStatements(meta, metadata, checkExport));
}
tails.push(...buildLocalExportStatements(meta, checkExport));
ensureStatementsHoisted(headers);
// FIXME ensure tail?
path.unshiftContainer('body', headers);
path.pushContainer('body', tails);
checkAssignOrUpdateExport(path, meta);
}
}
}
};
};
/**
* Remove all imports and exports from the file, and return all metadata
* needed to reconstruct the module's behavior.
* @return {ModuleMetadata}
*/
function normalizeModuleAndLoadMetadata(programPath) {
nameAnonymousExports(programPath);
const {local, source} = getModuleMetadata(programPath);
removeModuleDeclarations(programPath);
// Reuse the imported namespace name if there is one.
for (const [, metadata] of source) {
if (metadata.importsNamespace.size > 0) {
// This is kind of gross. If we stop using `loose: true` we should
// just make this destructuring assignment.
metadata.name = metadata.importsNamespace.values().next().value;
}
}
return {
exportName: 'exports',
exportNameListName: null,
local,
source
};
}
/**
* Get metadata about the imports and exports present in this module.
*/
function getModuleMetadata(programPath) {
const localData = getLocalExportMetadata(programPath);
const sourceData = new Map();
const getData = sourceNode => {
const source = sourceNode.value;
let data = sourceData.get(source);
if (!data) {
data = {
name: programPath.scope.generateUidIdentifier(
basename(source, extname(source))
).name,
interop: 'none',
loc: null,
// Data about the requested sources and names.
imports: new Map(),
// importsNamespace: import * as util from './a/b/util';
importsNamespace: new Set(),
// Metadata about data that is passed directly from source to export.
reexports: new Map(),
reexportNamespace: new Set(),
reexportAll: null,
};
sourceData.set(source, data);
}
return data;
};
programPath.get('body').forEach(child => {
if (child.isImportDeclaration()) {
const data = getData(child.node.source);
if (!data.loc) {
data.loc = child.node.loc;
}
child.get('specifiers').forEach(spec => {
if (spec.isImportDefaultSpecifier()) {
const localName = spec.get('local').node.name;
data.imports.set(localName, 'default');
const reexport = localData.get(localName);
if (reexport) {
localData.delete(localName);
reexport.names.forEach(name => {
data.reexports.set(name, 'default');
});
}
}
else if (spec.isImportNamespaceSpecifier()) {
const localName = spec.get('local').node.name;
assert(
data.importsNamespace.size === 0,
`Duplicate import namespace: ${localName}`
);
data.importsNamespace.add(localName);
const reexport = localData.get(localName);
if (reexport) {
localData.delete(localName);
reexport.names.forEach(name => {
data.reexportNamespace.add(name);
});
}
}
else if (spec.isImportSpecifier()) {
const importName = spec.get('imported').node.name;
const localName = spec.get('local').node.name;
data.imports.set(localName, importName);
const reexport = localData.get(localName);
if (reexport) {
localData.delete(localName);
reexport.names.forEach(name => {
data.reexports.set(name, importName);
});
}
}
});
}
else if (child.isExportAllDeclaration()) {
const data = getData(child.node.source);
if (!data.loc) {
data.loc = child.node.loc;
}
data.reexportAll = {
loc: child.node.loc,
};
}
else if (child.isExportNamedDeclaration() && child.node.source) {
const data = getData(child.node.source);
if (!data.loc) {
data.loc = child.node.loc;
}
child.get('specifiers').forEach(spec => {
if (!spec.isExportSpecifier()) {
throw spec.buildCodeFrameError('Unexpected export specifier type');
}
const importName = spec.get('local').node.name;
const exportName = spec.get('exported').node.name;
data.reexports.set(exportName, importName);
if (exportName === '__esModule') {
throw exportName.buildCodeFrameError('Illegal export "__esModule".');
}
});
}
});
for (const metadata of sourceData.values()) {
if (metadata.importsNamespace.size > 0) {
metadata.interop = 'namespace';
continue;
}
let needsDefault = false;
let needsNamed = false;
for (const importName of metadata.imports.values()) {
if (importName === 'default') {
needsDefault = true;
}
else {
needsNamed = true;
}
}
for (const importName of metadata.reexports.values()) {
if (importName === 'default') {
needsDefault = true;
}
else {
needsNamed = true;
}
}
if (needsDefault && needsNamed) {
// TODO(logan): Using the namespace interop here is unfortunate. Revisit.
metadata.interop = 'namespace';
}
else if (needsDefault) {
metadata.interop = 'default';
}
}
return {
local: localData,
source: sourceData,
};
}
/**
* Get metadata about local variables that are exported.
* @return {Map<string, LocalExportMetadata>}
*/
function getLocalExportMetadata(programPath){
const bindingKindLookup = new Map();
programPath.get('body').forEach(child => {
let kind;
if (child.isImportDeclaration()) {
kind = 'import';
}
else {
if (child.isExportDefaultDeclaration()) {
child = child.get('declaration');
}
if (child.isExportNamedDeclaration() && child.node.declaration) {
child = child.get('declaration');
}
if (child.isFunctionDeclaration()) {
kind = 'hoisted';
}
else if (child.isClassDeclaration()) {
kind = 'block';
}
else if (child.isVariableDeclaration({ kind: 'var' })) {
kind = 'var';
}
else if (child.isVariableDeclaration()) {
kind = 'block';
}
else {
return;
}
}
Object.keys(child.getOuterBindingIdentifiers()).forEach(name => {
bindingKindLookup.set(name, kind);
});
});
const localMetadata = new Map();
const getLocalMetadata = idPath => {
const localName = idPath.node.name;
let metadata = localMetadata.get(localName);
if (!metadata) {
const kind = bindingKindLookup.get(localName);
if (kind === undefined) {
throw idPath.buildCodeFrameError(`Exporting local "${localName}", which is not declared.`);
}
metadata = {
names: [],
kind,
};
localMetadata.set(localName, metadata);
}
return metadata;
};
programPath.get('body').forEach(child => {
if (child.isExportNamedDeclaration() && !child.node.source) {
if (child.node.declaration) {
const declaration = child.get('declaration');
const ids = declaration.getOuterBindingIdentifierPaths();
Object.keys(ids).forEach(name => {
if (name === '__esModule') {
throw declaration.buildCodeFrameError('Illegal export "__esModule".');
}
getLocalMetadata(ids[name]).names.push(name);
});
}
else {
child.get('specifiers').forEach(spec => {
const local = spec.get('local');
const exported = spec.get('exported');
if (exported.node.name === '__esModule') {
throw exported.buildCodeFrameError('Illegal export "__esModule".');
}
getLocalMetadata(local).names.push(exported.node.name);
});
}
}
else if (child.isExportDefaultDeclaration()) {
const declaration = child.get('declaration');
if (
declaration.isFunctionDeclaration() ||
declaration.isClassDeclaration()
) {
getLocalMetadata(declaration.get('id')).names.push('default');
}
else {
// These should have been removed by the nameAnonymousExports() call.
throw declaration.buildCodeFrameError('Unexpected default expression export.');
}
}
});
return localMetadata;
}
/**
* Ensure that all exported values have local binding names.
*/
function nameAnonymousExports(programPath) {
// Name anonymous exported locals.
programPath.get('body').forEach(child => {
if (!child.isExportDefaultDeclaration()) {
return;
}
// export default foo;
const declaration = child.get('declaration');
if (declaration.isFunctionDeclaration()) {
if (!declaration.node.id) {
declaration.node.id = declaration.scope.generateUidIdentifier('default');
}
}
else if (declaration.isClassDeclaration()) {
if (!declaration.node.id) {
declaration.node.id = declaration.scope.generateUidIdentifier('default');
}
}
else {
const id = declaration.scope.generateUidIdentifier('default');
const namedDecl = babelTypes.exportNamedDeclaration(null, [
babelTypes.exportSpecifier(babelTypes.identifier(id.name), babelTypes.identifier('default')),
]);
namedDecl._blockHoist = child.node._blockHoist;
const varDecl = babelTypes.variableDeclaration('var', [
babelTypes.variableDeclarator(id, declaration.node),
]);
varDecl._blockHoist = child.node._blockHoist;
child.replaceWithMultiple([namedDecl, varDecl]);
}
});
}
function removeModuleDeclarations(programPath) {
programPath.get('body').forEach(child => {
if (child.isImportDeclaration()) {
child.remove();
}
else if (child.isExportNamedDeclaration()) {
if (child.node.declaration) {
child.node.declaration._blockHoist = child.node._blockHoist;
child.replaceWith(child.node.declaration);
}
else {
child.remove();
}
}
else if (child.isExportDefaultDeclaration()) {
// export default foo;
const declaration = child.get('declaration');
if (
declaration.isFunctionDeclaration() ||
declaration.isClassDeclaration()
) {
declaration._blockHoist = child.node._blockHoist;
child.replaceWith(declaration);
}
else {
// These should have been removed by the nameAnonymousExports() call.
throw declaration.buildCodeFrameError('Unexpected default expression export.');
}
}
else if (child.isExportAllDeclaration()) {
child.remove();
}
});
}
/**
* Perform all of the generic ES6 module rewriting needed to handle initial
* module processing. This function will rewrite the majority of the given
* program to reference the modules described by the returned metadata,
* and returns a list of statements for use when initializing the module.
*/
function rewriteModuleStatementsAndPrepare(path) {
path.node.sourceType = 'script';
const meta = normalizeModuleAndLoadMetadata(path);
return meta;
}
/**
* Create the runtime initialization statements for a given requested source.
* These will initialize all of the runtime import/export logic that
* can't be handled statically by the statements created by
* buildExportInitializationStatements().
*/
function buildNamespaceInitStatements(meta, metadata, checkExport) {
const statements = [];
const {localImportName, localImportDefaultName} = getLocalImportName(metadata);
for (const exportName of metadata.reexportNamespace) {
// Assign export to namespace object.
checkExport(exportName);
statements.push(buildExport({exportName, localName: localImportName}));
}
// Source code:
// import {color2 as color2Alias, color3, color4, color5} from 'xxx';
// export {default as b} from 'xxx';
// export {color2Alias};
// export {color3};
// let color5Renamed = color5
// export {color5Renamed};
// Only two entries in metadata.reexports:
// 'color2Alias' => 'color2'
// 'color3' => 'color3',
// 'b' => 'default'
//
// And consider:
// export {default as defaultAsBB} from './xx/yy';
// export {exportSingle} from './xx/yy';
// No entries in metadata.imports, and 'default' exists in metadata.reexports.
for (const entry of metadata.reexports.entries()) {
const exportName = entry[0];
checkExport(exportName);
statements.push(
(localImportDefaultName || entry[1] === 'default')
? buildExport({exportName, localName: localImportName})
: buildExport({exportName, namespace: localImportName, propName: entry[1]})
);
}
if (metadata.reexportAll) {
const statement = buildNamespaceReexport(
meta,
metadata.name,
checkExport
);
statement.loc = metadata.reexportAll.loc;
// Iterate props creating getter for each prop.
statements.push(statement);
}
return statements;
}
/**
* Create a re-export initialization loop for a specific imported namespace.
*/
function buildNamespaceReexport(meta, namespace, checkExport) {
checkExport();
return babelTemplate.statement(`
(function() {
for (var key in NAMESPACE) {
if (NAMESPACE == null || !NAMESPACE.hasOwnProperty(key) || key === 'default' || key === '__esModule') return;
VERIFY_NAME_LIST;
exports[key] = NAMESPACE[key];
}
})();
`)({
NAMESPACE: namespace,
VERIFY_NAME_LIST: meta.exportNameListName
? babelTemplate.statement(`
if (Object.prototype.hasOwnProperty.call(EXPORTS_LIST, key)) return;
`)({EXPORTS_LIST: meta.exportNameListName})
: null
});
}
function buildRequireStatements(types, source, metadata) {
let headers = [];
const loadExpr = types.callExpression(
types.identifier('require'),
// replace `require('./src/xxx')` to `require('./lib/xxx')`
// for echarts and zrender in old npm or webpack.
[types.stringLiteral(source.replace('/src/', '/lib/'))]
);
// side effect import: import 'xxx';
if (isSideEffectImport(metadata)) {
let header = types.expressionStatement(loadExpr);
header.loc = metadata.loc;
headers.push(header);
}
else {
const {localImportName, localImportDefaultName} = getLocalImportName(metadata);
let reqHeader = types.variableDeclaration('var', [
types.variableDeclarator(
types.identifier(localImportName),
loadExpr
)
]);
reqHeader.loc = metadata.loc;
headers.push(reqHeader);
if (!localImportDefaultName) {
// src:
// import {someInZrUtil1 as someInZrUtil1Alias, zz} from 'zrender/core/util';
// metadata.imports:
// Map { 'someInZrUtil1Alias' => 'someInZrUtil1', 'zz' => 'zz' }
for (const importEntry of metadata.imports) {
headers.push(
babelTemplate.statement(`var IMPORTNAME = NAMESPACE.PROPNAME;`)({
NAMESPACE: localImportName,
IMPORTNAME: importEntry[0],
PROPNAME: importEntry[1]
})
);
}
}
}
return headers;
}
function getLocalImportName(metadata) {
const localImportDefaultName = getDefaultName(metadata.imports);
assert(
!localImportDefaultName || metadata.imports.size === 1,
'Forbiden that both import default and others.'
);
return {
localImportName: localImportDefaultName || metadata.name,
localImportDefaultName
};
}
function getDefaultName(map) {
for (const entry of map) {
if (entry[1] === 'default') {
return entry[0];
}
}
}
function buildLocalExportStatements(meta, checkExport) {
let tails = [];
// All local export, for example:
// Map {
// 'localVarMame' => {
// names: [ 'exportName1', 'exportName2' ],
// kind: 'var'
// },
for (const localEntry of meta.local) {
for (const exportName of localEntry[1].names) {
checkExport(exportName);
tails.push(buildExport({exportName, localName: localEntry[0]}));
}
}
return tails;
}
function createExportChecker() {
let someHasBeenExported;
return function checkExport(exportName) {
assert(
!someHasBeenExported || exportName !== 'default',
`Forbiden that both export default and others.`
);
someHasBeenExported = true;
};
}
function buildExport({exportName, namespace, propName, localName}) {
const exportDefault = exportName === 'default';
const head = exportDefault ? 'module.exports' : `exports.${exportName}`;
let opt = {};
// FIXME
// Does `PRIORITY`, `LOCATION_PARAMS` recognised as babel-template placeholder?
// We have to do this for workaround temporarily.
if (/^[A-Z0-9_]+$/.test(localName)) {
opt[localName] = localName;
}
return babelTemplate.statement(
localName
? `${head} = ${localName};`
: `${head} = ${namespace}.${propName};`
)(opt);
}
/**
* Consider this case:
* export var a;
* function inject(b) {
* a = b;
* }
* It will be transpiled to:
* var a;
* exports.a = 1;
* function inject(b) {
* a = b;
* }
* That is a wrong transpilation, because the `export.a` will not
* be assigned as `b` when `inject` called.
* Of course, it can be transpiled correctly as:
* var _locals = {};
* var a;
* Object.defineProperty(exports, 'a', {
* get: function () { return _locals[a]; }
* };
* exports.a = a;
* function inject(b) {
* _locals[a] = b;
* }
* But it is not ES3 compatible.
* So we just forbiden this usage here.
*/
function checkAssignOrUpdateExport(programPath, meta) {
let visitor = {
// Include:
// `a++;` (no `path.get('left')`)
// `x += 1212`;
UpdateExpression: {
exit: function exit(path, scope) {
// console.log(arguments);
let left = path.get('left');
if (left && left.isIdentifier()) {
asertNotAssign(path, left.node.name);
}
}
},
// Include:
// `x = 5;` (`x` is an identifier.)
// `c.d = 3;` (but `c.d` is not an identifier.)
// `y = function () {}`
// Exclude:
// `var x = 121;`
// `export var x = 121;`
AssignmentExpression: {
exit: function exit(path) {
let left = path.get('left');
if (left.isIdentifier()) {
asertNotAssign(path, left.node.name);
}
}
}
};
function asertNotAssign(path, localName) {
// Ignore variables that is not in global scope.
if (programPath.scope.getBinding(localName) !== path.scope.getBinding(localName)) {
return;
}
for (const localEntry of meta.local) {
assert(
localName !== localEntry[0],
`An exported variable \`${localEntry[0]}\` is forbiden to be assigned.`
);
}
}
programPath.traverse(visitor);
}

View File

@ -0,0 +1,33 @@
/**
* Both used by zrender and echarts.
*/
module.exports = function ({types, template}, options) {
return {
visitor: {
IfStatement: {
exit(path) {
removeDEV(path);
}
}
}
};
};
module.exports.recheckDEV = function (code) {
let result = code.match(/.if\s*\([^()]*__DEV__/);
if (result
&& result[0].indexOf('`if') < 0
&& result[0].indexOf('if (typeof __DEV__') < 0
) {
throw new Error('__DEV__ is not removed.');
}
};
function removeDEV(path) {
if (path.node.test.name === '__DEV__') {
path.remove();
}
}

84
node_modules/zrender/build/build.js generated vendored Normal file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env node
const fsExtra = require('fs-extra');
const {resolve} = require('path');
const config = require('./config.js');
const commander = require('commander');
const {build, watch} = require('./helper');
const prePublish = require('./pre-publish');
function run() {
/**
* Tips for `commander`:
* (1) If arg xxx not specified, `commander.xxx` is undefined.
* Otherwise:
* If '-x, --xxx', `commander.xxx` can only be true/false, even if '--xxx yyy' input.
* If '-x, --xxx <some>', the 'some' string is required, or otherwise error will be thrown.
* If '-x, --xxx [some]', the 'some' string is optional, that is, `commander.xxx` can be boolean or string.
* (2) `node ./build/build.js --help` will print helper info and exit.
*/
commander
.usage('[options]')
.description('Build zrender and generate result files in directory `zrender/dist` ')
.option(
'--release',
'Build all for release'
)
.option(
'--prepublish',
'Build all for release'
)
.option(
'-w, --watch',
'Watch modifications of files and auto-compile to dist file (e.g., `zrender/dist/zrender.js`).'
)
.option(
'--min',
'Whether to compress the output file.'
)
.parse(process.argv);
let isWatch = !!commander.watch;
let isRelease = !!commander.release;
let isPrePublish = !!commander.prepublish;
let min = !!commander.min;
// Clear `echarts/dist`
if (isRelease) {
fsExtra.removeSync(getPath('./dist'));
}
if (isWatch) {
watch(config.create());
}
else if (isPrePublish) {
prePublish();
}
else if (isRelease) {
build([
config.create(false),
config.create(true)
]).then(function () {
prePublish();
}).catch(handleBuildError);
}
else {
build([config.create(min)]).catch(handleBuildError);
}
}
function handleBuildError(err) {
console.log(err);
}
/**
* @param {string} relativePath Based on zrender directory.
* @return {string} Absolute path.
*/
function getPath(relativePath) {
return resolve(__dirname, '../', relativePath);
}
run();

47
node_modules/zrender/build/config.js generated vendored Normal file
View File

@ -0,0 +1,47 @@
const uglifyPlugin = require('rollup-plugin-uglify');
const {resolve} = require('path');
// Based on echarts/
function getPath(relativePath) {
return resolve(__dirname, '../', relativePath);
}
/**
* @param {boolean} [min=false]
*/
function getPlugins(min) {
let plugins = [];
min && plugins.push(uglifyPlugin({
compress: {
// Eliminate __DEV__ code.
'global_defs': {
__DEV__: true
}
}
}));
return plugins;
}
/**
* @param {boolean} [min=false]
*/
exports.create = function (min) {
let postfixMin = min ? '.min' : '';
return {
plugins: getPlugins(min),
input: getPath(`./zrender.all.js`),
legacy: true, // Support IE8-
output: {
name: 'zrender',
format: 'umd',
legacy: true, // Must be declared both in inputOptions and outputOptions.
sourcemap: !min,
file: getPath(`dist/zrender${postfixMin}.js`)
},
watch: {
include: [getPath('./src/**'), getPath('./zrender*.js')]
}
};
};

265
node_modules/zrender/build/helper.js generated vendored Normal file
View File

@ -0,0 +1,265 @@
/**
* Both used by zrender and echarts.
*/
const assert = require('assert');
const rollup = require('rollup');
const path = require('path');
const fs = require('fs');
const fsExtra = require('fs-extra');
const babel = require('@babel/core');
const esm2cjsPlugin = require('./babel-plugin-transform-modules-commonjs-ec');
const removeDEVPlugin = require('./babel-plugin-transform-remove-dev');
/**
* @param {Array.<Object>} configs A list of rollup configs:
* See: <https://rollupjs.org/#big-list-of-options>
* For example:
* [
* {
* ...inputOptions,
* output: [outputOptions],
* watch: {chokidar, include, exclude}
* },
* ...
* ]
* @return {Promise}
*/
exports.build = function (configs) {
return new Promise(function (promiseResolve, promiseReject) {
let index = 0;
buildSingle();
function buildSingle() {
let singleConfig = configs[index++];
if (!singleConfig) {
promiseResolve();
return;
}
console.log(
color('fgCyan', 'dim')('\nBundles '),
color('fgCyan')(singleConfig.input),
color('fgCyan', 'dim')('=>'),
color('fgCyan')(singleConfig.output.file),
color('fgCyan', 'dim')(' ...')
);
rollup
.rollup(singleConfig)
.then(function (bundle) {
return bundle.write(singleConfig.output);
})
.then(function () {
console.log(
color('fgGreen', 'dim')('Created '),
color('fgGreen')(singleConfig.output.file),
color('fgGreen', 'dim')(' successfully.')
);
buildSingle();
})
.catch(function (err) {
console.log(color('fgRed')(err));
promiseReject();
});
}
});
};
/**
* @param {Object} singleConfig A single rollup config:
* See: <https://rollupjs.org/#big-list-of-options>
* For example:
* {
* ...inputOptions,
* output: [outputOptions],
* watch: {chokidar, include, exclude}
* }
*/
exports.watch = function (singleConfig) {
let watcher = rollup.watch(singleConfig);
watcher.on('event', function (event) {
// event.code can be one of:
// START — the watcher is (re)starting
// BUNDLE_START — building an individual bundle
// BUNDLE_END — finished building a bundle
// END — finished building all bundles
// ERROR — encountered an error while bundling
// FATAL — encountered an unrecoverable error
if (event.code !== 'START' && event.code !== 'END') {
console.log(
color('fgBlue')('[' + getTimeString() + ']'),
color('dim')('build'),
event.code.replace(/_/g, ' ').toLowerCase()
);
}
if (event.code === 'ERROR' || event.code === 'FATAL') {
printCodeError(event.error);
}
if (event.code === 'BUNDLE_END') {
printWatchResult(event);
}
});
};
/**
* @param {string} srcDir Absolute directory path.
* @param {Function} [cb] Params: {
* fileName: like 'some.js', without dir path.
* relativePath: relative to srcDir.
* absolutePath
* }
*/
exports.travelSrcDir = function (srcDir, cb) {
assert(fs.statSync(srcDir).isDirectory());
const regDir = /^[^.].*$/;
const regSrc = /^[^.].*[.]js$/;
doTravelSrcDir('.');
function doTravelSrcDir(relativePath) {
const absolutePath = path.resolve(srcDir, relativePath);
fs.readdirSync(absolutePath).forEach(fileName => {
const childAbsolutePath = path.resolve(absolutePath, fileName);
const stat = fs.statSync(childAbsolutePath);
if (stat.isDirectory()) {
if (regDir.test(fileName)) {
doTravelSrcDir(path.join(relativePath, fileName));
}
}
else if (stat.isFile()) {
if (regSrc.test(fileName)) {
cb({fileName, relativePath, absolutePath: childAbsolutePath});
}
}
});
}
};
/**
* @param {string} [opt]
* @param {string} [opt.inputPath] Absolute input path.
* @param {string} [opt.outputPath] Absolute output path.
* @param {string} [opt.preamble]
* @param {Function} [opt.transform]
* @param {Function} [opt.reserveDEV]
*/
exports.prePulishSrc = function ({inputPath, outputPath, preamble, transform, reserveDEV}) {
assert(inputPath && outputPath);
console.log(
color('fgGreen', 'dim')('[transform] '),
color('fgGreen')(inputPath),
color('fgGreen', 'dim')('...')
);
let plugins = [];
!reserveDEV && plugins.push(removeDEVPlugin);
plugins.push(esm2cjsPlugin);
let {code} = babel.transformFileSync(inputPath, {
plugins: plugins
});
!reserveDEV && removeDEVPlugin.recheckDEV(code);
if (transform) {
code = transform({code, inputPath, outputPath});
}
if (preamble) {
code = preamble + code;
}
fsExtra.ensureFileSync(outputPath);
fs.writeFileSync(outputPath, code, {encoding:'utf-8'});
};
function printWatchResult(event) {
console.log(
color('fgGreen', 'dim')('Created'),
color('fgGreen')(event.output.join(', ')),
color('fgGreen', 'dim')('in'),
color('fgGreen')(event.duration),
color('fgGreen', 'dim')('ms.')
);
}
function printCodeError(error) {
console.log('\n' + color()(error.code));
if (error.code === 'PARSE_ERROR') {
console.log(
color()('line'),
color('fgCyan')(error.loc.line),
color()('column'),
color('fgCyan')(error.loc.column),
color()('in'),
color('fgCyan')(error.loc.file)
);
}
if (error.frame) {
console.log('\n' + color('fgRed')(error.frame));
}
console.log(color('dim')('\n' + error.stack));
}
function getTimeString() {
return (new Date()).toLocaleString();
}
const COLOR_RESET = '\x1b[0m';
const COLOR_MAP = {
bright: '\x1b[1m',
dim: '\x1b[2m',
underscore: '\x1b[4m',
blink: '\x1b[5m',
reverse: '\x1b[7m',
hidden: '\x1b[8m',
fgBlack: '\x1b[30m',
fgRed: '\x1b[31m',
fgGreen: '\x1b[32m',
fgYellow: '\x1b[33m',
fgBlue: '\x1b[34m',
fgMagenta: '\x1b[35m',
fgCyan: '\x1b[36m',
fgWhite: '\x1b[37m',
bgBlack: '\x1b[40m',
bgRed: '\x1b[41m',
bgGreen: '\x1b[42m',
bgYellow: '\x1b[43m',
bgBlue: '\x1b[44m',
bgMagenta: '\x1b[45m',
bgCyan: '\x1b[46m',
bgWhite: '\x1b[47m'
};
/**
* Print colored text with `console.log`.
*
* Usage:
* let color = require('colorConsole');
* color('fgCyan')('some text'); // cyan text.
* color('fgCyan', 'bright')('some text'); // bright cyan text.
* color('fgCyan', 'bgRed')('some text') // cyan text and red background.
*/
let color = exports.color = function () {
let prefix = [];
for (let i = 0; i < arguments.length; i++) {
let color = COLOR_MAP[arguments[i]];
color && prefix.push(color);
}
prefix = prefix.join('');
return function (text) {
return prefix + text + COLOR_RESET;
};
};

32
node_modules/zrender/build/pre-publish.js generated vendored Normal file
View File

@ -0,0 +1,32 @@
/**
* Compatible with prevoius folder structure: `zrender/lib` exists in `node_modules`
*/
const path = require('path');
const fsExtra = require('fs-extra');
const {color, travelSrcDir, prePulishSrc} = require('./helper');
const ecDir = path.resolve(__dirname, '..');
const srcDir = path.resolve(__dirname, '../src');
const libDir = path.resolve(__dirname, '../lib');
module.exports = function () {
fsExtra.removeSync(libDir);
fsExtra.ensureDirSync(libDir);
travelSrcDir(srcDir, ({fileName, relativePath, absolutePath}) => {
prePulishSrc({
inputPath: absolutePath,
outputPath: path.resolve(libDir, relativePath, fileName)
});
});
prePulishSrc({
inputPath: path.resolve(ecDir, 'zrender.all.js'),
outputPath: path.resolve(ecDir, 'index.js')
});
console.log(color('fgGreen', 'bright')('All done.'));
};