|
5 | 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +import * as fs from 'fs-extra'; |
8 | 9 | import * as paths from 'path';
|
9 | 10 | import { readJsonFile, writeJsonFile } from './json-file';
|
10 | 11 | import { NpmRegistry, NodePackage, PublishedNodePackage, sortByKey } from './npm-registry';
|
11 | 12 | import { Extension, ExtensionPackage, RawExtensionPackage } from './extension-package';
|
12 | 13 | import { ExtensionPackageCollector } from './extension-package-collector';
|
13 | 14 |
|
14 | 15 | export type ApplicationLog = (message?: any, ...optionalParams: any[]) => void;
|
| 16 | +export type ApplicationModuleLoader = (modulePath: string) => string; |
15 | 17 | export type ApplicationPackageTarget = 'browser' | 'electron';
|
16 | 18 | export class ApplicationPackageOptions {
|
17 | 19 | readonly projectPath: string;
|
@@ -55,7 +57,10 @@ export class ApplicationPackage extends ApplicationPackageOptions {
|
55 | 57 | */
|
56 | 58 | get extensionPackages(): ReadonlyArray<ExtensionPackage> {
|
57 | 59 | if (!this._extensionPackages) {
|
58 |
| - const collector = new ExtensionPackageCollector(raw => this.newExtensionPackage(raw)); |
| 60 | + const collector = new ExtensionPackageCollector( |
| 61 | + raw => this.newExtensionPackage(raw), |
| 62 | + this.loadModule |
| 63 | + ); |
59 | 64 | this._extensionPackages = collector.collect(this.pck);
|
60 | 65 | }
|
61 | 66 | return this._extensionPackages;
|
@@ -202,4 +207,19 @@ export class ApplicationPackage extends ApplicationPackageOptions {
|
202 | 207 | });
|
203 | 208 | }
|
204 | 209 |
|
| 210 | + protected _moduleLoader: undefined | ApplicationModuleLoader; |
| 211 | + get loadModule(): ApplicationModuleLoader { |
| 212 | + if (!this._moduleLoader) { |
| 213 | + const loaderPath = this.path('.application-module-loader.js'); |
| 214 | + fs.writeFileSync(loaderPath, 'module.exports = modulePath => require.resolve(modulePath);'); |
| 215 | + this._moduleLoader = require(loaderPath) as ApplicationModuleLoader; |
| 216 | + fs.removeSync(loaderPath); |
| 217 | + } |
| 218 | + return this._moduleLoader!; |
| 219 | + } |
| 220 | + |
| 221 | + resolveModulePath(moduleName: string, ...segments: string[]): string { |
| 222 | + return paths.resolve(this.loadModule(moduleName + '/package.json'), '..', ...segments); |
| 223 | + } |
| 224 | + |
205 | 225 | }
|
0 commit comments