Skip to content

Commit

Permalink
fix: fix cjs module problem
Browse files Browse the repository at this point in the history
  • Loading branch information
imtaotao committed Jun 30, 2021
1 parent a732e45 commit 1b94018
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/runtime/core/src/module/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ export class App {
this.isHtmlMode = isHtmlMode;
this.cjsModules = {
exports: {},
module: this.cjsModules,
module: null,
require: (key: string) => context.externals[key],
[__GARFISH_EXPORTS__]: this.customExports,
};
this.cjsModules.module = this.cjsModules;
this.customLoader = customLoader;

// Save all the resources to address
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/micro-component/src/actuator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export class Actuator {
this.env = {
...env,
exports: {},
module: this.env,
module: null,
// Env has a higher priority
require: (key) => this.env[key] || EXTERNALS[key],
};
this.env.module = this.env;
}

execScript() {
Expand Down
12 changes: 6 additions & 6 deletions packages/runtime/micro-component/src/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export function loadComponent(
} else {
const data = await loader.loadComponent(url);
const actuator = new Actuator(data.resourceManager, env);
const exports = actuator.execScript().exports;
let exports = actuator.execScript().exports;
if (typeof adapter === 'function') {
adapter(exports);
exports = adapter(exports);
}
result = exports.default || exports;
result = exports;
cacheComponents[urlWithVersion] = result;
}
} catch (err) {
Expand Down Expand Up @@ -98,11 +98,11 @@ export function loadComponentSync(

try {
const actuator = new Actuator(manager, env);
const exports = actuator.execScript().exports;
let exports = actuator.execScript().exports;
if (typeof adapter === 'function') {
adapter(exports);
exports = adapter(exports);
}
result = exports.default || exports;
result = exports;
cacheComponents[urlWithVersion] = result;
} catch (err) {
if (typeof error === 'function') {
Expand Down

0 comments on commit 1b94018

Please sign in to comment.