Skip to content

Commit

Permalink
[fix] allow transpiling code under node_modules (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Nov 15, 2020
1 parent e95886d commit 773d9f9
Show file tree
Hide file tree
Showing 31 changed files with 231 additions and 72 deletions.
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-critical-css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@
"expectTag": true,
"devOnly": true,
"defaultInstall": false
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@
"expectTag": true,
"devOnly": true,
"defaultInstall": false
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-inferno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@
"electrode-archetype-opt-react",
"electrode-archetype-opt-inferno"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-phantomjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@
"expectTag": true,
"devOnly": true,
"defaultInstall": false
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@
"expectTag": true,
"devOnly": true,
"defaultInstall": false
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-react-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@
"expectTag": true,
"devOnly": false,
"defaultInstall": false
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-sinon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
"expectTag": true,
"devOnly": true,
"defaultInstall": false
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-opt-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
"expectTag": true,
"devOnly": true,
"defaultInstall": false
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-webpack-dll-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
"functions": 85,
"lines": 79,
"cache": true
},
"fyn": {
"dependencies": {
"webpack-config-composer": "../webpack-config-composer"
}
}
}
5 changes: 5 additions & 0 deletions packages/electrode-archetype-webpack-dll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@
"functions": 45,
"lines": 66,
"cache": true
},
"fyn": {
"devDependencies": {
"electrode-archetype-webpack-dll-dev": "../electrode-archetype-webpack-dll-dev"
}
}
}
3 changes: 2 additions & 1 deletion packages/subapp-pbundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"subapp-util": "../subapp-util"
},
"devDependencies": {
"@xarc/app": "../xarc-app"
"@xarc/app": "../xarc-app",
"subapp-pkg-util": "../subapp-pkg-util"
}
},
"nyc": {
Expand Down
3 changes: 2 additions & 1 deletion packages/subapp-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"subapp-util": "../subapp-util"
},
"devDependencies": {
"@xarc/app": "../xarc-app"
"@xarc/app": "../xarc-app",
"subapp-pkg-util": "../subapp-pkg-util"
}
},
"nyc": {
Expand Down
3 changes: 3 additions & 0 deletions packages/subapp-redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
"dependencies": {
"subapp-util": "../subapp-util",
"subapp-web": "../subapp-web"
},
"devDependencies": {
"subapp-pkg-util": "../subapp-pkg-util"
}
}
}
4 changes: 3 additions & 1 deletion packages/subapp-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
"subapp-util": "../subapp-util"
},
"devDependencies": {
"@xarc/app": "../xarc-app"
"@xarc/app": "../xarc-app",
"electrode-react-webapp": "../electrode-react-webapp",
"subapp-pkg-util": "../subapp-pkg-util"
}
},
"nyc": {
Expand Down
43 changes: 2 additions & 41 deletions packages/xarc-app-dev/src/config/archetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,12 @@

import { XarcOptions } from "./opt2/xarc-options";
import { getDevArchetypeLegacy } from "./options";
import { createGitIgnoreDir } from "../lib/utils";
const Fs = require("fs");
const _ = require("lodash");
const getEnvProxy = require("./env-proxy");
const Path = require("path");
import { saveXarcOptions } from "../lib/utils";

let cachedArchetype = null;

function createElectrodeTmpDir(eTmpDir = ".etmp") {
createGitIgnoreDir(Path.resolve(eTmpDir), "Electrode tmp dir");
}

function jsonStringifyReplacer(key, value) {
if (value instanceof RegExp) {
return value.toString();
}
return value;
}

function saveArchetypeConfig(config) {
const filename = `${config.eTmpDir}/xarc-options.json`;
const copy = { ...config, pkg: undefined, devPkg: undefined };
let existStr;

try {
existStr = Fs.readFileSync(filename, "utf-8");
} catch (err) {
//
}

const str = JSON.stringify(copy, jsonStringifyReplacer, 2);
if (str !== existStr) {
try {
createElectrodeTmpDir(config.eTmpDir);

Fs.writeFileSync(filename, str);
} catch (err) {
console.error(
`Unable to save development options to ${filename} - this will cause other failures.\n`,
err
);
}
}
}

/**
* Get development options
*
Expand Down Expand Up @@ -82,7 +43,7 @@ module.exports = function getDevOptions(user: XarcOptions = {}) {
addOnFeatures: undefined
});

saveArchetypeConfig(legacy);
saveXarcOptions(legacy);

cachedArchetype = legacy;

Expand Down
16 changes: 16 additions & 0 deletions packages/xarc-app-dev/src/config/opt2/babel-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ export type BabelOptions = {
*/
transformClassProps?: boolean | { loose: boolean };

/**
* List of RegExp to match files that should be included for transpiling.
*
* By default, files under node_modules are not transpiled.
*
* You can set this to control that. ie: to compile everything under node_modules, use `[/node_modules/]`
*/
includeRegExp?: RegExp[];

/**
* List of RegExp to match files that should not be transpiled by babel.
*
* This is checked after includeRegExp
*/
excludeRegExp?: RegExp[];

// DEPRECATE: looseClassProps?: boolean;

// DEPRECATE:
Expand Down
53 changes: 51 additions & 2 deletions packages/xarc-app-dev/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-var-requires, no-console */

import * as readPkgUp from "read-pkg-up";
import * as pkgUp from "pkg-up";
Expand Down Expand Up @@ -69,6 +69,25 @@ export function createGitIgnoreDir(dir, comment) {
}
}

const regExpSig = "@xarc/__RegExp__@";

export const jsonStringifier = (key, value) => {
if (value instanceof RegExp) {
return `${regExpSig}${value.toString()}`;
} else {
return value;
}
};

export const jsonParser = (key, value) => {
if (typeof value === "string" && value.startsWith(regExpSig)) {
const m = value.substr(regExpSig.length).match(/\/(.*)\/(.*)?/);
return new RegExp(m[1], m[2] || "");
} else {
return value;
}
};

let cachedXarcOptions;

export function loadXarcOptions(dir: string = process.cwd()) {
Expand All @@ -78,7 +97,7 @@ export function loadXarcOptions(dir: string = process.cwd()) {
const filename = Path.join(dir, ".etmp/xarc-options.json");
try {
const data = Fs.readFileSync(filename, "utf-8");
return (cachedXarcOptions = JSON.parse(data));
return (cachedXarcOptions = JSON.parse(data, jsonParser));
} catch (err) {
// eslint-disable-next-line
console.error(ck`
Expand All @@ -100,6 +119,36 @@ xarc's development code.
}
}

function createElectrodeTmpDir(eTmpDir = ".etmp") {
createGitIgnoreDir(Path.resolve(eTmpDir), "Electrode tmp dir");
}

export function saveXarcOptions(config) {
const filename = `${config.eTmpDir}/xarc-options.json`;
const copy = { ...config, pkg: undefined, devPkg: undefined };
let existStr;

try {
existStr = Fs.readFileSync(filename, "utf-8");
} catch (err) {
//
}

const str = JSON.stringify(copy, jsonStringifier, 2);
if (str !== existStr) {
try {
createElectrodeTmpDir(config.eTmpDir);

Fs.writeFileSync(filename, str);
} catch (err) {
console.error(
`Unable to save development options to ${filename} - this will cause other failures.\n`,
err
);
}
}
}

export function detectCSSModule(xOptions) {
const cssModuleSupport = _.get(xOptions, "webpack.cssModuleSupport", undefined);
if (cssModuleSupport === undefined) {
Expand Down
5 changes: 5 additions & 0 deletions packages/xarc-opt-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@
"@xarc/opt-eslint",
"electrode-archetype-opt-eslint"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/xarc-opt-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@
"@xarc/opt-jest",
"electrode-archetype-opt-jest"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/xarc-opt-karma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@
"@xarc/opt-karma",
"electrode-archetype-opt-karma"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/xarc-opt-less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@
"@xarc/opt-less",
"electrode-archetype-opt-less"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/xarc-opt-mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@
"@xarc/opt-mocha",
"electrode-archetype-opt-mocha"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/xarc-opt-postcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@
"@xarc/opt-postcss",
"electrode-archetype-opt-postcss"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
5 changes: 5 additions & 0 deletions packages/xarc-opt-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@
"electrode-archetype-opt-react",
"electrode-archetype-opt-inferno"
]
},
"fyn": {
"devDependencies": {
"opt-archetype-check": "../opt-archetype-check"
}
}
}
Loading

0 comments on commit 773d9f9

Please sign in to comment.