Support for cnpm and use electron as devDependence instead of electron-prebuilt
This commit is contained in:
Родитель
cac4e98631
Коммит
8df7c24f2b
|
@ -6,6 +6,7 @@
|
||||||
"typings": "lib/src/main.d.ts",
|
"typings": "lib/src/main.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc",
|
"compile": "tsc",
|
||||||
|
"watch": "tsc -w",
|
||||||
"prepublish": "npm run compile",
|
"prepublish": "npm run compile",
|
||||||
"test": "mocha --compilers ts:ts-node/register ./test/*.ts",
|
"test": "mocha --compilers ts:ts-node/register ./test/*.ts",
|
||||||
"lint": "tslint \"src/**/*.ts\" \"test/**/*.ts\""
|
"lint": "tslint \"src/**/*.ts\" \"test/**/*.ts\""
|
||||||
|
@ -54,7 +55,7 @@
|
||||||
"@types/yargs": "^6.6.0",
|
"@types/yargs": "^6.6.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"chai-as-promised": "^6.0.0",
|
"chai-as-promised": "^6.0.0",
|
||||||
"electron-prebuilt": "^1.4.13",
|
"electron": "^1.4.13",
|
||||||
"mocha": "^3.2.0",
|
"mocha": "^3.2.0",
|
||||||
"ts-node": "^3.0.2",
|
"ts-node": "^3.0.2",
|
||||||
"tslint": "^4.5.1",
|
"tslint": "^4.5.1",
|
||||||
|
|
|
@ -28,6 +28,8 @@ class Rebuilder {
|
||||||
nodeGypPath: string;
|
nodeGypPath: string;
|
||||||
prodDeps: Set<string>;
|
prodDeps: Set<string>;
|
||||||
rebuilds: (() => Promise<void>)[];
|
rebuilds: (() => Promise<void>)[];
|
||||||
|
realModulePaths: Array<string>;
|
||||||
|
realNodeModulesPaths: Array<string>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public lifecycle: EventEmitter,
|
public lifecycle: EventEmitter,
|
||||||
|
@ -42,6 +44,8 @@ class Rebuilder {
|
||||||
this.ABI = nodeAbi.getAbi(electronVersion, 'electron');
|
this.ABI = nodeAbi.getAbi(electronVersion, 'electron');
|
||||||
this.prodDeps = extraModules.reduce((acc, x) => acc.add(x), new Set());
|
this.prodDeps = extraModules.reduce((acc, x) => acc.add(x), new Set());
|
||||||
this.rebuilds = [];
|
this.rebuilds = [];
|
||||||
|
this.realModulePaths = [];
|
||||||
|
this.realNodeModulesPaths = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async rebuild() {
|
async rebuild() {
|
||||||
|
@ -184,19 +188,40 @@ class Rebuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuildAllModulesIn(nodeModulesPath: string, prefix = '') {
|
rebuildAllModulesIn(nodeModulesPath: string, prefix = '') {
|
||||||
d('scanning:', nodeModulesPath);
|
// While we use `cnpm`, it will make a circle scanning the dep tree.
|
||||||
|
// We also need to ensure that the `node_modules` which we are scanning has never came before.
|
||||||
|
const realNodeModulesPath = fs.realpathSync(nodeModulesPath);
|
||||||
|
if (this.realNodeModulesPaths.indexOf(realNodeModulesPath) > -1) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.realNodeModulesPaths.push(realNodeModulesPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
d('scanning:', realNodeModulesPath);
|
||||||
|
|
||||||
|
for (const modulePath of fs.readdirSync(realNodeModulesPath)) {
|
||||||
|
// If we use `cnpm` to install mudules, it will be rebuilded failed,
|
||||||
|
// because of some same modules rebuilded twice or more.
|
||||||
|
// Need to ensure one dep only be rebuilded once.
|
||||||
|
const finalPath = path.resolve(nodeModulesPath, modulePath);
|
||||||
|
const realPath = fs.realpathSync(finalPath);
|
||||||
|
|
||||||
|
if (this.realModulePaths.indexOf(realPath) > -1) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
this.realModulePaths.push(realPath);
|
||||||
|
}
|
||||||
|
|
||||||
for (const modulePath of fs.readdirSync(nodeModulesPath)) {
|
|
||||||
if (this.prodDeps[`${prefix}${modulePath}`]) {
|
if (this.prodDeps[`${prefix}${modulePath}`]) {
|
||||||
this.rebuilds.push(() => this.rebuildModuleAt(path.resolve(nodeModulesPath, modulePath)));
|
this.rebuilds.push(() => this.rebuildModuleAt(realPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modulePath.startsWith('@')) {
|
if (modulePath.startsWith('@')) {
|
||||||
this.rebuildAllModulesIn(path.resolve(nodeModulesPath, modulePath), `${modulePath}/`);
|
this.rebuildAllModulesIn(realPath, `${modulePath}/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.existsSync(path.resolve(nodeModulesPath, modulePath, 'node_modules'))) {
|
if (fs.existsSync(path.resolve(nodeModulesPath, modulePath, 'node_modules'))) {
|
||||||
this.rebuildAllModulesIn(path.resolve(nodeModulesPath, modulePath, 'node_modules'));
|
this.rebuildAllModulesIn(path.resolve(realPath, 'node_modules'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче