Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle config: inline internal hook wrapper #28978

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.