Skip to content

Commit

Permalink
dont use 'tsc' when build test. only use rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
giabao committed Apr 20, 2019
1 parent 9ed1761 commit 4a3a7a2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 23 additions & 26 deletions scripts/rollup.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@ 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');

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')
}),
];

Expand All @@ -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;
7 changes: 5 additions & 2 deletions scripts/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -48,4 +49,6 @@ function main() {
}
}

// usage: node [options] scripts/tsc.js [tsc arguments]
// note: tsc will run in cwd: srcDir
main();
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"rangy-classapplier": "classapplier/bundles/index.umd"
}
});
requirejs(['./index.test.js'], function () {
requirejs(['./index.test.amd.js'], function () {
QUnit.start();
});
</script>
Expand Down
6 changes: 2 additions & 4 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down

0 comments on commit 4a3a7a2

Please sign in to comment.