From 71d6765b05af47db6555a23ea5d08f762a58d207 Mon Sep 17 00:00:00 2001 From: haiqin Date: Sat, 27 Jan 2024 14:38:40 +0800 Subject: [PATCH] chore: switch bundler to tsup --- packages/inula-reactive/bench/index.js | 24 ++++---- packages/inula-reactive/package.json | 5 +- packages/inula-reactive/rollup.config.js | 59 ------------------- packages/inula-reactive/tsup.config.js | 20 +++++++ .../inula/scripts/rollup/rollup.config.js | 2 +- .../view-parser/src/test/ElementUnit.test.ts | 2 +- 6 files changed, 36 insertions(+), 76 deletions(-) delete mode 100644 packages/inula-reactive/rollup.config.js create mode 100644 packages/inula-reactive/tsup.config.js diff --git a/packages/inula-reactive/bench/index.js b/packages/inula-reactive/bench/index.js index dd54b97f..317d65e7 100644 --- a/packages/inula-reactive/bench/index.js +++ b/packages/inula-reactive/bench/index.js @@ -20,7 +20,7 @@ import chalk from 'chalk'; import * as solid from './solid-reactive.js'; import * as reactively from '@reactively/core'; import Table from 'cli-table'; -import { reactive, computed } from '../dist/index.js'; +import { reactive, computed, RNode } from '../dist/index.js'; const BATCHED = true; const RUNS_PER_TIER = 150; @@ -44,10 +44,9 @@ const SOLUTIONS = { const isSolution = (layers, answer) => answer.every((_, i) => SOLUTIONS[layers][i] === _); async function main() { - debugger const report = {}; - // report.solid = { fn: runSolid, runs: [] }; - // report.reactively = { fn: runReactively, runs: [], avg: [] }; + report.solid = { fn: runSolid, runs: [] }; + report.reactively = { fn: runReactively, runs: [], avg: [] }; report.inluaReactive = { fn: runInulaReactive, runs: [], avg: [] }; // report.inluaDeepReactive = { fn: runInulaDeepReactive, runs: [], avg: [] }; @@ -91,7 +90,6 @@ async function main() { slowestLib = lib; } } - report[fastestLib].runs[i] = chalk.green(report[fastestLib].runs[i].toFixed(2)); report[slowestLib].runs[i] = chalk.red(report[slowestLib].runs[i].toFixed(2)); } @@ -113,10 +111,10 @@ async function start(runner, layers) { function runInulaReactive(layers, done) { const start = { - a: new reactive(1), - b: new reactive(2), - c: new reactive(3), - d: new reactive(4), + a: new RNode(1), + b: new RNode(2), + c: new RNode(3), + d: new RNode(4), }; let layer = start; @@ -124,10 +122,10 @@ function runInulaReactive(layers, done) { for (let i = layers; i--; ) { layer = (m => { return { - a: new computed(() => m.b.get()), - b: new computed(() => m.a.get() - m.c.get()), - c: new computed(() => m.b.get() + m.d.get()), - d: new computed(() => m.c.get()), + a: new RNode(() => m.b.get()), + b: new RNode(() => m.a.get() - m.c.get()), + c: new RNode(() => m.b.get() + m.d.get()), + d: new RNode(() => m.c.get()), }; })(layer); } diff --git a/packages/inula-reactive/package.json b/packages/inula-reactive/package.json index e6aa5452..01d1256b 100644 --- a/packages/inula-reactive/package.json +++ b/packages/inula-reactive/package.json @@ -5,7 +5,7 @@ "main": "dist/index.js", "type": "module", "scripts": { - "build": "rollup --config ./rollup.config.js", + "build": "tsup", "test": "jest --config=jest.config.js", "bench": "node --experimental-specifier-resolution=node --inspect ./bench/index.js" }, @@ -16,6 +16,7 @@ "devDependencies": { "chalk": "^5.3.0", "cli-table": "^0.3.11", - "tslib": "^2.6.2" + "tsup": "^6.7.0", + "esbuild-plugin-replace": "^1.4.0" } } diff --git a/packages/inula-reactive/rollup.config.js b/packages/inula-reactive/rollup.config.js deleted file mode 100644 index 0ae91f8b..00000000 --- a/packages/inula-reactive/rollup.config.js +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Technologies Co.,Ltd. - * - * openInula is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -import nodeResolve from '@rollup/plugin-node-resolve'; -import babel from '@rollup/plugin-babel'; -import path from 'path'; -import replace from '@rollup/plugin-replace'; - -const extensions = ['.js', '.ts', '.tsx']; - -const getBasicPlugins = mode => { - return [ - nodeResolve({ - extensions, - modulesOnly: true, - }), - babel({ - exclude: 'node_modules/**', - configFile: path.join(__dirname, './babel.config.cjs'), - extensions, - }), - replace({ - values: { - 'process.env.NODE_ENV': `"${mode}"`, - }, - preventAssignment: true, - }), - ]; -}; - -function genConfig(mode) { - return { - input: path.resolve(__dirname, 'src', 'index.ts'), - output: [ - { - file:path.resolve(__dirname, 'dist', 'index.js'), - format: 'esm', - }, - ], - plugins: [ - ...getBasicPlugins(mode), - ], - }; -} - - -export default [genConfig('production')]; diff --git a/packages/inula-reactive/tsup.config.js b/packages/inula-reactive/tsup.config.js new file mode 100644 index 00000000..8b4416c0 --- /dev/null +++ b/packages/inula-reactive/tsup.config.js @@ -0,0 +1,20 @@ +import {defineConfig} from 'tsup'; +import {replace} from 'esbuild-plugin-replace'; + +export default defineConfig({ + esbuildPlugins: [ + replace({ + values: { + 'process.env.NODE_ENV': '\'production\'', + }, + })], + entry: [ + 'src/index.ts', + ], + format: [ + 'cjs', + 'esm', + ], + treeshake: true, + clean: true, +}); diff --git a/packages/inula/scripts/rollup/rollup.config.js b/packages/inula/scripts/rollup/rollup.config.js index 42952ac2..5b759981 100644 --- a/packages/inula/scripts/rollup/rollup.config.js +++ b/packages/inula/scripts/rollup/rollup.config.js @@ -50,7 +50,7 @@ const getBasicPlugins = mode => { }), babel({ exclude: 'node_modules/**', - configFile: path.join(__dirname, '../../babel.config.cjs'), + configFile: path.join(__dirname, '../../babel.config.js'), babelHelpers: 'runtime', extensions, }), diff --git a/packages/transpiler/view-parser/src/test/ElementUnit.test.ts b/packages/transpiler/view-parser/src/test/ElementUnit.test.ts index 116670f3..f539be4c 100644 --- a/packages/transpiler/view-parser/src/test/ElementUnit.test.ts +++ b/packages/transpiler/view-parser/src/test/ElementUnit.test.ts @@ -202,4 +202,4 @@ describe('ElementUnit', () => { expect(t.isStringLiteral((firstChild as HTMLUnit).tag, { value: 'div' })).toBeTruthy(); expect((firstChild as HTMLUnit).children![0].type).toBe('text'); }); -}); \ No newline at end of file +});