Skip to content

Commit

Permalink
enable tests by adding babel ts tranform plugin
Browse files Browse the repository at this point in the history
remove flow plugin
  • Loading branch information
saihaj committed May 14, 2021
1 parent db11cba commit 647b7dd
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .babelrc-deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugins": [
"@babel/plugin-transform-flow-strip-types",
["./resources/add-extension-to-import-paths", { "extension": "js" }],
"@babel/plugin-transform-typescript",
["./resources/add-extension-to-import-paths", { "extension": "ts" }],
"./resources/inline-invariant"
]
}
2 changes: 1 addition & 1 deletion .babelrc-npm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"plugins": [
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-transform-typescript",
"./resources/inline-invariant"
],
"env": {
Expand Down
9 changes: 2 additions & 7 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"plugins": ["@babel/plugin-transform-flow-strip-types"],
"presets": [
[
"@babel/preset-env",
{ "bugfixes": true, "targets": { "node": "current" } }
]
]
"plugins": ["@babel/plugin-transform-typescript"],
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
}
2 changes: 1 addition & 1 deletion .mocharc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
throw-deprecation: true
check-leaks: true
require:
- '@babel/register'
- 'resources/ts-register.js'
92 changes: 47 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"scripts": {
"preversion": ". ./resources/checkgit.sh && npm ci",
"version": "node resources/gen-version.js && npm test && git add src/version.js",
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.js",
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.ts",
"changelog": "node resources/gen-changelog.js",
"benchmark": "node benchmark/benchmark.js",
"test": "npm run lint && npm run check && npm run testonly && npm run prettier:check && npm run check:spelling && npm run check:integrations",
"lint": "eslint --cache .",
"check": "flow check",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.js",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts",
"testonly:cover": "nyc npm run testonly",
"prettier": "prettier --write --list-different .",
"prettier:check": "prettier --check .",
Expand All @@ -46,7 +46,7 @@
"devDependencies": {
"@babel/core": "7.14.0",
"@babel/eslint-parser": "7.13.14",
"@babel/plugin-transform-flow-strip-types": "7.13.0",
"@babel/plugin-transform-typescript": "7.13.0",
"@babel/preset-env": "7.14.1",
"@babel/register": "7.13.16",
"@typescript-eslint/eslint-plugin": "4.22.1",
Expand Down
2 changes: 1 addition & 1 deletion resources/build-deno.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (require.main === module) {
const destPath = path.join('./denoDist', filepath);

fs.mkdirSync(path.dirname(destPath), { recursive: true });
if (filepath.endsWith('.js')) {
if (filepath.endsWith('.ts') && !filepath.endsWith('.d.ts')) {
const options = { babelrc: false, configFile: './.babelrc-deno.json' };
const output = babel.transformFileSync(srcPath, options).code + '\n';
writeGeneratedFile(destPath, output);
Expand Down
10 changes: 3 additions & 7 deletions resources/build-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ if (require.main === module) {
const destPath = path.join('./npmDist', filepath);

fs.mkdirSync(path.dirname(destPath), { recursive: true });
if (filepath.endsWith('.js')) {
const flowBody =
'// @flow strict\n\n' + fs.readFileSync(srcPath, 'utf-8');
fs.writeFileSync(destPath + '.flow', flowBody);

if (filepath.endsWith('.ts') && !filepath.endsWith('.d.ts')) {
const cjs = babelBuild(srcPath, { envName: 'cjs' });
writeGeneratedFile(destPath, cjs);
writeGeneratedFile(destPath.replace(/\.ts$/, '.js'), cjs);

const mjs = babelBuild(srcPath, { envName: 'mjs' });
writeGeneratedFile(destPath.replace(/\.js$/, '.mjs'), mjs);
writeGeneratedFile(destPath.replace(/\.ts$/, '.mjs'), mjs);
} else if (filepath.endsWith('.d.ts')) {
fs.copyFileSync(srcPath, destPath);
}
Expand Down
3 changes: 3 additions & 0 deletions resources/ts-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

require('@babel/register')({ extensions: ['.ts'] });

0 comments on commit 647b7dd

Please sign in to comment.