Skip to content

Commit

Permalink
fix: update js2c for mjs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 7, 2021
1 parent 21ac035 commit 3a6eac8
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ index 3be3f2364dd252bcdd668c699a0e7ae1e754e873..b2af1bce312ffca44e7005e11f92327e

bool Exists(const char* id);
diff --git a/tools/js2c.py b/tools/js2c.py
index 4af54c3fa00602f9d0ce5cc4dca253d425048706..0830e4b9f86d66be760c7f608fd65fa4518dc684 100755
index 4af54c3fa00602f9d0ce5cc4dca253d425048706..ef6572732b8c0464fb22536aed9171b4182c373d 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -38,6 +38,8 @@ import functools
Expand Down Expand Up @@ -90,7 +90,7 @@ index 4af54c3fa00602f9d0ce5cc4dca253d425048706..0830e4b9f86d66be760c7f608fd65fa4
if split[0] == 'deps':
split = ['internal'] + split
else: # `lib/**/*.js` so drop the 'lib' part
@@ -141,7 +147,7 @@ def NormalizeFileName(filename):
@@ -141,23 +147,36 @@ def NormalizeFileName(filename):
return os.path.splitext(filename)[0]


Expand All @@ -99,22 +99,29 @@ index 4af54c3fa00602f9d0ce5cc4dca253d425048706..0830e4b9f86d66be760c7f608fd65fa4
# Build source code lines
definitions = []
initializers = []
@@ -151,13 +157,26 @@ def JS2C(source_files, target):
for filename in source_files['.mjs']:
AddModule(filename, definitions, initializers)

- for filename in source_files['.js']:
- AddModule(filename, definitions, initializers)
- for filename in source_files['.mjs']:
- AddModule(filename, definitions, initializers)
-
- config_def, config_size = handle_config_gypi(source_files['config.gypi'])
- definitions.append(config_def)
+ # Electron: Expose fs module without asar support.
+ if filename == 'lib/fs.js':
+ # Node's 'fs' and 'internal/fs/<filename> have lazy-loaded circular
+ # dependencies. So to expose the unmodified Node 'fs' functionality here,
+ # we have to copy both 'fs' *and* 'internal/fs/<filename>' files and modify the
+ # copies to depend on each other instead of on our asarified 'fs' code.
+ AddModule('lib/original-fs.js', definitions, initializers, lambda _: ReadFile(filename).replace("require('internal/fs/", "require('internal/original-fs/"))
+ elif filename.startswith('lib/internal/fs/'):
+ original_fs_filename = filename.replace('internal/fs/', 'internal/original-fs/')
+ AddModule(original_fs_filename, definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')"))
+ for extension in source_files.keys():
+ for filename in source_files[extension]:
+ if extension == '.js' or extension == '.mjs':
+ AddModule(filename, definitions, initializers)
+
+ # Electron: Expose fs module without asar support.
+ if filename == 'lib/fs.js':
+ # Node's 'fs' and 'internal/fs/<filename> have lazy-loaded circular
+ # dependencies. So to expose the unmodified Node 'fs' functionality here,
+ # we have to copy both 'fs' *and* 'internal/fs/<filename>' files and modify the
+ # copies to depend on each other instead of on our asarified 'fs' code.
+ AddModule('lib/original-fs.js', definitions, initializers, lambda _: ReadFile(filename).replace("require('internal/fs/", "require('internal/original-fs/"))
+ elif filename.startswith('lib/internal/fs/'):
+ original_fs_filename = filename.replace('internal/fs/', 'internal/original-fs/')
+ AddModule(original_fs_filename, definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')"))
+
+ config_size = 0
+ if not only_js:
Expand All @@ -129,7 +136,7 @@ index 4af54c3fa00602f9d0ce5cc4dca253d425048706..0830e4b9f86d66be760c7f608fd65fa4
write_if_chaged(out, target)


@@ -213,18 +232,22 @@ def main():
@@ -213,18 +232,21 @@ def main():
)
parser.add_argument('--target', help='output file')
parser.add_argument('--verbose', action='store_true', help='output file')
Expand All @@ -147,8 +154,7 @@ index 4af54c3fa00602f9d0ce5cc4dca253d425048706..0830e4b9f86d66be760c7f608fd65fa4
- JS2C(source_files, options.target)
-
+ if options.only_js:
+ # Should have exactly 3 types: `.js`, `.mjs`
+ assert len(source_files) == 2
+ assert len(source_files) == 1
+ else:
+ # Should have exactly 3 types: `.js`, `.mjs` and `.gypi`
+ assert len(source_files) == 3
Expand Down

0 comments on commit 3a6eac8

Please sign in to comment.