Skip to content

Commit

Permalink
Bundle config: inline internal hook wrapper (#28978)
Browse files Browse the repository at this point in the history
Bundle config: inline internal hook wrapper

Instead of reading this wrapper from 2 files for "start" and "end" and
then string modifying the templates, just inline them like the other
wrappers in this file.
  • Loading branch information
kassens authored May 3, 2024
1 parent 38cd73b commit 0a0a3af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 39 deletions.
38 changes: 19 additions & 19 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const {resolve} = require('path');
const {readFileSync} = require('fs');
const {signFile, getSigningToken} = require('signedsource');
const {bundleTypes, moduleTypes} = require('./bundles');

Expand Down Expand Up @@ -30,19 +28,25 @@ const {RECONCILER} = moduleTypes;

const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;

function registerInternalModuleStart(globalName) {
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js');
const file = readFileSync(path);
return String(file).trim();
function wrapWithRegisterInternalModule(source) {
return `\
'use strict';
if (
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
'function'
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}

function registerInternalModuleStop(globalName) {
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleEnd.js');
const file = readFileSync(path);

// Remove the 'use strict' directive from the footer.
// This directive is only meaningful when it is the first statement in a file or function.
return String(file).replace(USE_STRICT_HEADER_REGEX, '').trim();
${source}
if (
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
'function'
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
}
`;
}

const license = ` * Copyright (c) Meta Platforms, Inc. and affiliates.
Expand Down Expand Up @@ -496,11 +500,7 @@ function wrapWithTopLevelDefinitions(

// Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
// This allows the Timeline to de-emphasize (dim) internal stack frames.
source = `
${registerInternalModuleStart(globalName)}
${source}
${registerInternalModuleStop(globalName)}
`;
source = wrapWithRegisterInternalModule(source);
break;
}
}
Expand Down
10 changes: 0 additions & 10 deletions scripts/rollup/wrappers/registerInternalModuleBegin.js

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/rollup/wrappers/registerInternalModuleEnd.js

This file was deleted.

0 comments on commit 0a0a3af

Please sign in to comment.