Skip to content

Commit 5847453

Browse files
committed
fix: fix no-entry bug
1 parent 7906a01 commit 5847453

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

dev/react/public/a.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// console.log('########', require);
1+
console.log('########', require);

packages/browser-vm/src/pluginify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function rewriteAppAndSandbox(
6767
{
6868
// For application of environment variables
6969
...env,
70-
...app.getExecScriptEnv(false),
70+
...app.getExecScriptEnv(options?.noEntry),
7171
},
7272
url,
7373
options,

packages/core/src/module/app.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { StyleManager, TemplateManager } from '@garfish/loader';
22
import {
3+
Text,
34
warn,
45
assert,
6+
hasOwn,
57
remove,
6-
Text,
78
isJs,
89
isObject,
910
isPromise,
11+
toBoolean,
1012
findTarget,
1113
evalWithEnv,
1214
transformUrl,
@@ -181,14 +183,14 @@ export class App {
181183
code,
182184
true,
183185
url,
184-
options.async,
186+
options?.async,
185187
);
186188
code += url ? `\n//# sourceURL=${url}\n` : '';
187189

188-
if (!env['window']) {
190+
if (!hasOwn(env, 'window')) {
189191
env = {
190-
window: this.global,
191192
...env,
193+
window: this.global,
192194
};
193195
}
194196

@@ -298,6 +300,7 @@ export class App {
298300
if (this.esModule) return {};
299301
if (noEntry) {
300302
return {
303+
require: this.cjsModules.require,
301304
[__GARFISH_EXPORTS__]: this.customExports,
302305
[__GARFISH_GLOBAL_ENV__]: this.globalEnvVariables,
303306
};
@@ -488,7 +491,7 @@ export class App {
488491
const { url, scriptCode } = jsManager;
489492
this.execScript(scriptCode, {}, url || this.appInfo.entry, {
490493
async: false,
491-
noEntry: Boolean(entryManager.findAttributeValue(node, 'no-entry')),
494+
noEntry: toBoolean(entryManager.findAttributeValue(node, 'no-entry')),
492495
});
493496
} else if (__DEV__) {
494497
const async = entryManager.findAttributeValue(node, 'async');

packages/utils/__tests__/runtimeUtils.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ describe('Garfish shared runtimeUtils', () => {
4949
});
5050

5151
it('toBoolean', () => {
52+
expect(toBoolean('')).toBe(true);
5253
expect(toBoolean('false')).toBe(false);
53-
[0, 1, '', 'a', , false, true, null, undefined, {}, () => {}].forEach(
54+
[0, 1, 'a', false, true, null, undefined, {}, () => {}].forEach(
5455
(val) => {
5556
expect(toBoolean(val)).toBe(Boolean(val));
5657
},

packages/utils/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ export function assert(condition: any, msg?: string | Error) {
163163
}
164164

165165
export function toBoolean(val: any) {
166-
return val === 'false' ? false : Boolean(val);
166+
if (val === '') return true;
167+
if (val === 'false') return false;
168+
return Boolean(val);
167169
}
168170

169171
export function remove<T>(list: Array<T> | Set<T>, el: T) {

0 commit comments

Comments
 (0)