From 4a3a7a268ad9c275803743d0ce3903c5c1ebeb5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=CC=80i=20Vie=CC=A3=CC=82t=20Tha=CC=80nh?= Date: Sat, 20 Apr 2019 22:43:25 +0700 Subject: [PATCH] dont use 'tsc' when build test. only use rollup --- .gitignore | 2 +- package.json | 15 +++--- scripts/rollup.config.test.ts | 49 +++++++++---------- scripts/tsc.ts | 7 ++- .../{index.html => index.amd.html} | 2 +- test/tsconfig.json | 6 +-- 6 files changed, 40 insertions(+), 41 deletions(-) rename test/classapplier/{index.html => index.amd.html} (93%) diff --git a/.gitignore b/.gitignore index 6b49637f..99590512 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ node_modules *.ts.map *.tsbuildinfo *.test.js -*.test.iife.js +*.test.amd.js *.test.d.ts /test/*.d.ts !/test/typings.d.ts diff --git a/package.json b/package.json index 4ddc857b..20f183b3 100644 --- a/package.json +++ b/package.json @@ -37,19 +37,20 @@ "scripts": { "postinstall": "echo 'https://github.com/qunitjs/qunit/issues/1389' && patch -i qunit.patch node_modules/qunit/qunit/qunit.js", "clean": "rimraf dist .rpt2_cache", - "tsc:scripts": "tsc -b scripts/tsconfig.json", - "tsc:src": "node $NODE_DEBUG_OPTION scripts/tsc.js", - "tsc:test": "tsc -b test/", "dist-prepare": "node scripts/dist-prepare.js", + "tsc:scripts": "tsc -b scripts/tsconfig.json", + "watch:tsc:scripts": "tsc -b scripts/tsconfig.json --watch --pretty", + "tsc:src": "node $NODE_DEBUG_OPTION scripts/tsc.js -b", + "watch:tsc:src": "node scripts/tsc.js -b --watch --pretty", "rollup:src": "rollup -c scripts/rollup.config.js", - "rollup:test": "rollup -c scripts/rollup.config.test.js", + "watch:rollup:src": "FORCE_COLOR=1 rollup -c scripts/rollup.config.js --watch", + "build:test": "rollup -c scripts/rollup.config.test.js", + "watch:test": "FORCE_COLOR=1 rollup -c scripts/rollup.config.test.js --watch", "build:src": "npm-run-all tsc:src rollup:src", - "build:test": "npm-run-all --parallel tsc:test rollup:test", "build": "run-s tsc:scripts build:src build:test", "prerelease": "run-s clean build dist-prepare", "release": "node scripts/publish.js", - "watch:src": "TODO FORCE_COLOR=1 rollup -c --watch", - "watch": "TODO run-p -l watch:types watch:js", + "watch": "run-p -l watch:*", "test": "echo 'pls browse test/*.html for testing'" }, "main": "./bundles/index.umd.js", diff --git a/scripts/rollup.config.test.ts b/scripts/rollup.config.test.ts index 11fef8a1..54e9a82a 100644 --- a/scripts/rollup.config.test.ts +++ b/scripts/rollup.config.test.ts @@ -9,6 +9,7 @@ import * as glob from 'glob'; import typescript from 'rollup-plugin-typescript2' import {modules, projectRoot} from "./util"; import {resolve, join} from "path"; +import {ModuleFormat, RollupOptions} from "rollup"; const testDir = resolve(projectRoot, 'test'); @@ -16,15 +17,7 @@ const plugins = [ nodeResolve(), commonjs(), typescript({ - tsconfig: resolve(testDir, 'tsconfig.json'), - tsconfigOverride: { - compilerOptions: { - target: "esnext", - module: "esnext", - declaration: false, - declarationMap: false, - } - } + tsconfig: resolve(testDir, 'tsconfig.json') }), ]; @@ -35,23 +28,27 @@ const external = ['rangy2', ...modules.map(n => 'rangy-' + n)]; const globals = {}; external.forEach(n => Object.assign(globals, {[n]: 'rangy'})); +function iifeConfig(f: string, format: ModuleFormat = 'iife'): RollupOptions { + f = join(testDir, f); + return { + input: [f], + output: { + format, + file: f.replace(/\.ts$/, format == 'iife'? '.js' : `.${format}.js`), + name: 'unnamed', + globals, + sourcemap: true + }, + external, + plugins, + } +} + const configs = glob - .sync('**/*.test.ts', {cwd: testDir}) - .map(f => join(testDir, f)) - .map((f) => { - const n = f.substr(0, f.length - 3); // remove `.ts` - return { - input: [f], - output: { - format: 'iife', - file: n + '.iife.js', - name: 'unnamed', - globals, - sourcemap: true - }, - external, - plugins, - } - }); + .sync('**/*.ts', {cwd: testDir}) + .filter(f => !f.endsWith('.d.ts')) + .map(f => iifeConfig(f)); +// push amdTestExampleConfig +configs.push(iifeConfig("classapplier/index.test.ts", 'amd')); export default configs; diff --git a/scripts/tsc.ts b/scripts/tsc.ts index 0edf8b62..89cef0cb 100644 --- a/scripts/tsc.ts +++ b/scripts/tsc.ts @@ -33,8 +33,9 @@ function writeTsConfig(name: string, es: boolean) { function tsc(es: boolean): boolean { modules.forEach(n => writeTsConfig(n, es)); - console.log(`$ tsc -b #es=${es}`); - const r = spawnSync('tsc', ['-b'], { + const args = process.argv.slice(2); //argv[0] is 'node', argv[1] is this script (scripts/tsc.js) + console.log(`$ tsc ${args.join(' ')} #es=${es}`); + const r = spawnSync('tsc', args, { stdio:'inherit', cwd: srcDir, }); @@ -48,4 +49,6 @@ function main() { } } +// usage: node [options] scripts/tsc.js [tsc arguments] +// note: tsc will run in cwd: srcDir main(); diff --git a/test/classapplier/index.html b/test/classapplier/index.amd.html similarity index 93% rename from test/classapplier/index.html rename to test/classapplier/index.amd.html index 41104d9b..5a8fc5b0 100644 --- a/test/classapplier/index.html +++ b/test/classapplier/index.amd.html @@ -22,7 +22,7 @@ "rangy-classapplier": "classapplier/bundles/index.umd" } }); - requirejs(['./index.test.js'], function () { + requirejs(['./index.test.amd.js'], function () { QUnit.start(); }); diff --git a/test/tsconfig.json b/test/tsconfig.json index 820df8ca..2f1db626 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,12 +1,10 @@ { "compilerOptions": { - "target": "es5", - "module": "umd", + "target": "esnext", + "module": "esnext", "moduleResolution": "node", "sourceMap": true, "stripInternal": true, - "declaration": true, - "declarationMap": true, "baseUrl": ".", "paths": { "rangy2": ["../src/core"],