zrender-nightly 5.6.1-dev.20240717 → 5.6.1-dev.20240718

Sign up to get free protection for your applications and to get access to all the features.
package/build/build.js ADDED
@@ -0,0 +1,118 @@
1
+ // const typescript = require('@rollup/plugin-typescript');
2
+ const typescript = require('rollup-plugin-typescript2');
3
+ const replace = require('@rollup/plugin-replace');
4
+ const rollup = require('rollup');
5
+ const path = require('path');
6
+ const processs = require('process');
7
+ const chalk = require('chalk');
8
+ const progress = require('./progress');
9
+ const UglifyJS = require('uglify-js');
10
+ const fs = require('fs');
11
+
12
+ function current() {
13
+ return (new Date()).toLocaleString();
14
+ }
15
+
16
+ function createInputOption(env, isWatch) {
17
+ return {
18
+ input: path.resolve(__dirname, '../index.ts'),
19
+ plugins: [
20
+ typescript({
21
+ clean: !isWatch,
22
+ tsconfigOverride: {
23
+ compilerOptions: {
24
+ // Rollup don't use CommonJS by default.
25
+ module: 'ES2015',
26
+ sourceMap: true,
27
+ // Use the esm d.ts
28
+ declaration: false
29
+ }
30
+ }
31
+ }),
32
+ replace({
33
+ preventAssignment: true,
34
+ 'process.env.NODE_ENV': JSON.stringify(env)
35
+ }),
36
+ progress({
37
+ scope: {
38
+ total: 0
39
+ }
40
+ })
41
+ ]
42
+ };
43
+ }
44
+
45
+ const outputOption = {
46
+ format: 'umd',
47
+ file: path.resolve(__dirname, '../dist/zrender.js'),
48
+ sourcemap: true,
49
+ name: 'zrender'
50
+ };
51
+
52
+ function minify(outPath) {
53
+ const code = fs.readFileSync(outPath, 'utf-8');
54
+ const uglifyResult = UglifyJS.minify(code);
55
+ if (uglifyResult.error) {
56
+ throw new Error(uglifyResult.error);
57
+ }
58
+ fs.writeFileSync(outPath, uglifyResult.code, 'utf-8');
59
+ }
60
+
61
+ if (processs.argv.includes('--watch')) {
62
+ const watcher = rollup.watch({
63
+ ...createInputOption('development', true),
64
+ output: [outputOption],
65
+ watch: {
66
+ clearScreen: true
67
+ }
68
+ });
69
+ watcher.on('event', event => {
70
+ switch(event.code) {
71
+ // case 'START':
72
+ // console.log(chalk.green('Begin to watch'));
73
+ // break;
74
+ case 'BUNDLE_START':
75
+ console.log(
76
+ chalk.gray(current()),
77
+ chalk.blue('File changed. Begin to bundle')
78
+ );
79
+ break;
80
+ case 'BUNDLE_END':
81
+ console.log(
82
+ chalk.gray(current()),
83
+ chalk.green('Finished bundle')
84
+ );
85
+ break;
86
+ case 'ERROR':
87
+ console.log(
88
+ chalk.gray(current()),
89
+ chalk.red(event.error)
90
+ );
91
+ break;
92
+ }
93
+ });
94
+ }
95
+ else {
96
+ // Unminified
97
+ rollup.rollup({
98
+ ...createInputOption('development', false)
99
+ }).then(bundle => {
100
+ bundle.write(outputOption)
101
+ .then(() => {
102
+ // Minified
103
+ if (process.argv.indexOf('--minify') >= 0) {
104
+ rollup.rollup({
105
+ ...createInputOption('production', false)
106
+ }).then(bundle => {
107
+ const file = outputOption.file.replace(/.js$/, '.min.js');
108
+ bundle.write(Object.assign(outputOption, {
109
+ file,
110
+ sourcemap: false
111
+ })).then(function () {
112
+ minify(file);
113
+ });
114
+ });
115
+ }
116
+ });
117
+ });
118
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,48 @@
1
+ const fs = require('fs');
2
+ const { execSync } = require('child_process');
3
+
4
+ const packageJsonPath = __dirname + '/../package.json';
5
+ const nightlyPackageName = 'zrender-nightly';
6
+
7
+ function updateVersion(version) {
8
+ const isNext = process.argv.includes('--next');
9
+ const parts = /(\d+)\.(\d+)\.(\d+)($|\-)/.exec(version);
10
+ if (!parts) {
11
+ throw new Error(`Invalid version number ${version}`);
12
+ }
13
+ // Add date to version.
14
+ const major = +parts[1];
15
+ let minor = +parts[2];
16
+ let patch = +parts[3];
17
+ const isStable = !parts[4];
18
+ if (isStable) {
19
+ // It's previous stable version. Dev version should be higher.
20
+ if (isNext) {
21
+ // Increase minor version for next branch.
22
+ minor++;
23
+ patch = 0;
24
+ }
25
+ else {
26
+ // Increase main version for master branch.
27
+ patch++;
28
+ }
29
+ }
30
+
31
+ const date = new Date().toISOString().replace(/:|T|\.|-/g, '').slice(0, 8);
32
+ return `${major}.${minor}.${patch}-dev.${date}`;
33
+ }
34
+
35
+
36
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
37
+ packageJson.name = nightlyPackageName;
38
+ const version = updateVersion(packageJson.version);
39
+
40
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
41
+
42
+ // Update version in package.json and package-lock.json
43
+ execSync(`npm version ${version} --git-tag-version=false`);
44
+
45
+ const entryPath = __dirname + '/../src/zrender.ts';
46
+ const entryFile = fs.readFileSync(entryPath, 'utf-8')
47
+ .replace(/export const version = '\S+'/, `export const version = '${version}'`);
48
+ fs.writeFileSync(entryPath, entryFile, 'utf-8');
@@ -0,0 +1,88 @@
1
+ const fs = require('fs-extra');
2
+ const chalk = require('chalk');
3
+ const ignore = require('ignore');
4
+ const { execSync } = require('node:child_process');
5
+
6
+ console.log();
7
+ console.log(chalk.yellowBright(`⚠️ You should have run ${chalk.bold('`npm run release`')} before running this script!`));
8
+ console.log();
9
+
10
+ // check versions in key dist files
11
+
12
+ console.log(chalk.yellow('🔎 Checking versions in dist files...'));
13
+
14
+ const fileVersions = [
15
+ 'package.json',
16
+ 'package-lock.json',
17
+ 'dist/zrender.js',
18
+ 'dist/zrender.min.js'
19
+ ].map(filePath => ({
20
+ file: filePath,
21
+ version: require('../' + filePath).version
22
+ }));
23
+
24
+ ['lib/zrender.js', 'src/zrender.ts'].forEach(filePath => {
25
+ const version = fs.readFileSync(filePath, 'utf-8').match(/export (?:var|const) version = '(\S+)'/)[1];
26
+ fileVersions.push({
27
+ file: filePath,
28
+ version: version
29
+ });
30
+ });
31
+
32
+ const versions = fileVersions.map(({ file, version }) => {
33
+ console.log(` ∟ The version in [${chalk.blueBright(file)}] is ${chalk.cyanBright.bold(version)}`);
34
+ return version;
35
+ });
36
+
37
+ if (new Set(versions).size !== 1) {
38
+ console.log();
39
+ console.error(chalk.red('❌ Version does not match! Please check and rerun the release script via:'));
40
+ console.log();
41
+ console.error(chalk.yellow(' npm run release'));
42
+ console.log();
43
+ process.exit(-1);
44
+ }
45
+
46
+ console.log();
47
+ console.log(chalk.green('✔️ Versions are all the same.'));
48
+ console.log();
49
+
50
+ console.log(chalk.yellow('🔎 Checking unexpected files that probably shouldn\'t be published...\n'));
51
+
52
+ // check if there are unexpected files that not in .npmignore
53
+ const npmignore = fs.readFileSync('.npmignore', 'utf-8');
54
+ const npmignorePatterns = npmignore
55
+ .split(/\r?\n/)
56
+ .filter(item => item && !item.startsWith('#'));
57
+
58
+ const untrackedFiles = execSync('git ls-files --others --exclude-standard', { encoding: 'utf-8' })
59
+ .trim()
60
+ .split('\n')
61
+ .map(escapeOctal);
62
+
63
+ if (untrackedFiles.length) {
64
+ const maybeUnexpectedFiles = ignore().add(npmignorePatterns).filter(untrackedFiles);
65
+ if (maybeUnexpectedFiles.length) {
66
+ console.error(chalk.red(`❌ Found ${maybeUnexpectedFiles.length} file(s) that are neither tracked by git nor ignored by .npmignore! Please double-check before publishing them to npm.`));
67
+ maybeUnexpectedFiles.forEach(filePath => {
68
+ console.log(' ∟ ' + filePath);
69
+ });
70
+ console.log();
71
+ process.exit(-1);
72
+ }
73
+ }
74
+
75
+ console.log(chalk.green('✔️ No unexpected files found.'));
76
+ console.log();
77
+
78
+ function escapeOctal(str) {
79
+ const matches = str.match(/(\\\d{3}){3}/g);
80
+ if (matches) {
81
+ matches.forEach(match => {
82
+ let encoded = '';
83
+ match.split('\\').forEach(code => !code || (encoded += '%' + parseInt(code, 8).toString(16)));
84
+ str = str.replace(match, decodeURI(encoded));
85
+ });
86
+ }
87
+ return str;
88
+ }
@@ -0,0 +1,67 @@
1
+ // Porcess generated lib files.
2
+ // Like adding js extension in the import statement.
3
+
4
+ const { transformImport } = require('./transformImport');
5
+ const globby = require('globby');
6
+ const path = require('path');
7
+ const fs = require('fs');
8
+ const chalk = require('chalk');
9
+ const rollup = require('rollup');
10
+ const nodeResolve = require('@rollup/plugin-node-resolve').default;
11
+
12
+ function addJsExtension(moduleName) {
13
+ // Ignore 'tslib'
14
+ if (!(moduleName.startsWith('.'))) {
15
+ return moduleName;
16
+ }
17
+ if (moduleName.endsWith('.ts')) {
18
+ // Replace ts with js
19
+ return moduleName.replace(/\.ts$/, '.js');
20
+ }
21
+ else if (moduleName.endsWith('.js')) {
22
+ return moduleName;
23
+ }
24
+ else {
25
+ return moduleName + '.js'
26
+ }
27
+ }
28
+
29
+ async function transform() {
30
+ const libFiles = await globby([
31
+ '**/*.js'
32
+ ], {
33
+ cwd: path.join(__dirname, '../lib'),
34
+ absolute: true
35
+ });
36
+
37
+ if (libFiles.length === 0) {
38
+ throw new Error('No lib files found.')
39
+ }
40
+
41
+ for (let file of libFiles) {
42
+ const code = fs.readFileSync(file, 'utf-8');
43
+ fs.writeFileSync(file, transformImport(code, addJsExtension), 'utf-8');
44
+ }
45
+
46
+ // Transform index;
47
+ const indexFile = path.join(__dirname, '../index.js');
48
+ fs.writeFileSync(
49
+ indexFile,
50
+ transformImport(
51
+ fs.readFileSync(indexFile, 'utf-8'),
52
+ (mduleName) => addJsExtension(mduleName).replace('./src', './lib')
53
+ )
54
+ )
55
+ }
56
+
57
+ transform().then(() => {
58
+ console.log(chalk.green('Added .js extensions.'));
59
+ console.log(chalk.gray('Start testing generated libs...'));
60
+ }).then(() => {
61
+ return rollup.rollup({
62
+ input: path.resolve(__dirname, '../index.js'),
63
+ plugins: [nodeResolve()]
64
+ });
65
+ }).then(() => {
66
+ console.log(chalk.green('Libs can be bundled!'));
67
+ });
@@ -0,0 +1,65 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ const chalk = require('chalk');
20
+ const path = require('path');
21
+
22
+ module.exports = function progress(options = {}) {
23
+ const scope = options.scope || {};
24
+ scope.finished = scope.finished || 0;
25
+ scope.total = scope.total || 0;
26
+
27
+ return {
28
+ name: 'progress',
29
+
30
+ buildStart() {
31
+ scope.finished = 0;
32
+ scope.total = 0;
33
+ },
34
+
35
+ load() {
36
+ // TODO More accurate total number
37
+ scope.total++;
38
+ },
39
+
40
+ transform(code, id) {
41
+ scope.finished++;
42
+ const filePath = path.relative(process.cwd(), id).split(path.sep).join('/');
43
+
44
+ const output = `[${scope.finished}/${scope.total}]: ${chalk.grey(filePath)}`;
45
+ if (process.stdout.isTTY) {
46
+ process.stdout.clearLine();
47
+ process.stdout.cursorTo(0);
48
+ process.stdout.write(output);
49
+ }
50
+ else {
51
+ console.log(output);
52
+ }
53
+ },
54
+
55
+ buildEnd() {
56
+ if (process.stdout.isTTY) {
57
+ process.stdout.clearLine();
58
+ process.stdout.cursorTo(0);
59
+ }
60
+ else {
61
+ console.log('');
62
+ }
63
+ }
64
+ };
65
+ };
@@ -0,0 +1,115 @@
1
+ // adding js extension in the import statement.
2
+
3
+ // Reference:
4
+ // https://regexr.com/47jlq
5
+ // https://gist.github.com/manekinekko/7e58a17bc62a9be47172
6
+ const regexp = /((?:(?:import)|(?:export))\s+?(?:(?:(?:[\w*\s{},\/]*)\s+from\s+?)|))(?:(?:"(.*?)")|(?:'(.*?)'))([\s]*?(?:;|$|))/g;
7
+
8
+ module.exports.transformImport = function (code, processModuleName) {
9
+ return code.replace(regexp, (str, prefix, moduleNameA, moduleNameB, postfix) => {
10
+ let moduleName = (moduleNameA === undefined ? moduleNameB : moduleNameA).trim();
11
+ const quote = moduleNameA === undefined ? "'" : '"';
12
+ return prefix + quote + processModuleName(moduleName) + quote + postfix;
13
+ // Not support other extensions.
14
+ });
15
+ }
16
+
17
+
18
+ const testCases = `import videos from './videos/index.js'
19
+
20
+ export default (socket, context) => {
21
+ // dynamically importing all the socket.io handler (it's dynamic import that happen at run time)
22
+ import {
23
+ something
24
+ } from "./test/okbb"
25
+
26
+ const f = 2;
27
+
28
+ import test from 'obb'
29
+
30
+
31
+ import {
32
+ Component
33
+ } from '@angular2/core';
34
+
35
+ import defaultMember from "module-0";
36
+
37
+ import * as name from "module-1 ";
38
+
39
+ import { member } from " module-2";
40
+
41
+ import { member as alias } from "module-3";
42
+
43
+ import { member1 , member2 } from "module-4";
44
+
45
+ import { member1 , member2 as alias2 , member3 as alias3 } from "module-5";
46
+
47
+ import defaultMember, { member, member } from "module-6";
48
+
49
+ import defaultMember, * as name from "module-7";
50
+
51
+ import "module-8";
52
+
53
+ import "module-9" // comment no problem
54
+
55
+ import {
56
+ AAAA,
57
+ // BBB
58
+ } from 'module-10';
59
+
60
+ import "module-b' // doesn't match -> the opening and closing quation mark are different
61
+
62
+ importing hya from 'ttt'
63
+
64
+ import fbsfrom ''
65
+
66
+
67
+ // Export expressions.
68
+ export { aaa };
69
+
70
+ export * from "module-11";
71
+
72
+ export { aaa } from "module-12";
73
+
74
+ // Should not be parsed
75
+ export default aaa;
76
+
77
+ export function bbb () {
78
+ };
79
+ `
80
+
81
+ module.exports.runTest = function () {
82
+ const expected = [
83
+ './videos/index.js',
84
+ './test/okbb',
85
+ 'obb',
86
+ '@angular2/core',
87
+ 'module-0',
88
+ 'module-1',
89
+ 'module-2',
90
+ 'module-3',
91
+ 'module-4',
92
+ 'module-5',
93
+ 'module-6',
94
+ 'module-7',
95
+ 'module-8',
96
+ 'module-9',
97
+ 'module-10',
98
+ 'module-11',
99
+ 'module-12'
100
+ ]
101
+ let cursor = 0;
102
+ module.exports.transformImport(testCases, (moduleName) => {
103
+ if (expected[cursor] !== moduleName) {
104
+ throw new Error(`Expected ${expected[cursor]}. Actual ${moduleName}`);
105
+ }
106
+ cursor++;
107
+ return moduleName;
108
+ })
109
+ if (cursor !== expected.length) {
110
+ throw new Error('Test failed');
111
+ }
112
+ console.log('All test passed!')
113
+ }
114
+
115
+ // module.exports.runTest();
package/dist/zrender.js CHANGED
@@ -7337,7 +7337,7 @@
7337
7337
  function registerSSRDataGetter(getter) {
7338
7338
  ssrDataGetter = getter;
7339
7339
  }
7340
- var version = '5.6.1-dev.20240717';
7340
+ var version = '5.6.1-dev.20240718';
7341
7341
 
7342
7342
  var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
7343
7343
  var DEFAULT_COMMON_STYLE = {