-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: eval('require'), fs import, process import optimized (#22)
* Update fs.ets and fs-polyfill.js * fix: Update eval require, fs import and process import
- Loading branch information
1 parent
27e22f0
commit 5f86754
Showing
4 changed files
with
26 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/sdk7-demo/entry/src/main/ets/default/pages/textutil.ets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import util from '@ohos.util'; | ||
//import util from '@ohos.util'; | ||
@Entry | ||
@Component | ||
struct TextPage { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import * as harmonyFS from './fs'; | ||
import * as process from 'process/browser' | ||
|
||
if (!globalThis.fs) { | ||
globalThis.harmonyFS = harmonyFS; | ||
|
||
if (!globalThis.process) { | ||
globalThis.process = require('process'); | ||
} | ||
globalThis.fs = harmonyFS; | ||
} | ||
|
||
if (!globalThis.process.versions) { | ||
globalThis.process.versions = {}; | ||
} | ||
if (!globalThis.process) { | ||
globalThis.process = process; | ||
} | ||
|
||
if (!globalThis.process.versions.node) { | ||
globalThis.process.versions.node = '0.0.0'; | ||
} | ||
if (!globalThis.process.versions) { | ||
globalThis.process.versions = {}; | ||
} | ||
|
||
globalThis['eval'] = function (functionBody) { | ||
if ('require' == functionBody) { | ||
return globalThis['require']; | ||
} | ||
if (!globalThis.process.versions.node) { | ||
globalThis.process.versions.node = '0.0.0'; | ||
} | ||
|
||
return eval(functionBody); | ||
}; | ||
globalThis['eval'] = function (functionBody) { | ||
if (functionBody == 'require') { | ||
return function protoRequire(moduleName){ | ||
if (moduleName == 'fs') { | ||
return harmonyFS; | ||
}else{ | ||
return __webpack_require__(moduleName) | ||
} | ||
}; | ||
} | ||
return eval(functionBody); | ||
}; | ||
|
||
globalThis['require'] = function (moduleName) { | ||
if (moduleName == 'fs') { | ||
return harmonyFS; | ||
} | ||
return require(moduleName); | ||
}; | ||
} |