Compare commits
No commits in common. "366ffe1ac9c3a61cc98212f8bb7d9e59b02a16f4" and "1f5eb3657e6699067003be2e8ff146aef0115355" have entirely different histories.
366ffe1ac9
...
1f5eb3657e
|
@ -69,40 +69,33 @@ function bundleNativeModulesPlugin() {
|
||||||
// Not edited
|
// Not edited
|
||||||
return edits.push([node.start, node.end]);
|
return edits.push([node.start, node.end]);
|
||||||
}
|
}
|
||||||
for (const matchString of ["require('loady')(__str_aName, __any)"]) {
|
const findLoady = (0, ast_matcher_1.default)("require('loady')(__str_aName, __any)");
|
||||||
const findLoady = (0, ast_matcher_1.default)(matchString);
|
const loadyMatches = findLoady(ast);
|
||||||
const loadyMatches = findLoady(ast);
|
if (loadyMatches?.length) {
|
||||||
if (loadyMatches?.length) {
|
for (const match of loadyMatches) {
|
||||||
for (const match of loadyMatches) {
|
if (markEdited(match.node, edits)) {
|
||||||
if (markEdited(match.node, edits)) {
|
const modulePath = loady_1.default.resolve(match.match.aName, id);
|
||||||
const modulePath = loady_1.default.resolve(match.match.aName, id);
|
const moduleFile = fs_1.default.readFileSync(modulePath);
|
||||||
const moduleFile = fs_1.default.readFileSync(modulePath);
|
const moduleB64 = moduleFile.toString("base64");
|
||||||
const moduleB64 = moduleFile.toString("base64");
|
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`);
|
||||||
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const matchString of [
|
const findNodeBuildGyp = (0, ast_matcher_1.default)("require('node-gyp-build')(__any)");
|
||||||
"require('node-gyp-build')(__any)",
|
const nodeBuildGypMatches = findNodeBuildGyp(ast);
|
||||||
"loadNAPI(__any)",
|
if (nodeBuildGypMatches?.length) {
|
||||||
]) {
|
for (const match of nodeBuildGypMatches) {
|
||||||
const findNodeBuildGyp = (0, ast_matcher_1.default)(matchString);
|
if (markEdited(match.node, edits)) {
|
||||||
const nodeBuildGypMatches = findNodeBuildGyp(ast);
|
const modulePath = node_gyp_build_1.default.path(path_1.default.dirname(id));
|
||||||
if (nodeBuildGypMatches?.length) {
|
const moduleName = modulePath
|
||||||
for (const match of nodeBuildGypMatches) {
|
.split("node_modules")
|
||||||
if (markEdited(match.node, edits)) {
|
.pop()
|
||||||
const modulePath = node_gyp_build_1.default.path(path_1.default.dirname(id));
|
.split("/")
|
||||||
const moduleName = modulePath
|
.slice(1)
|
||||||
.split("node_modules")
|
.shift();
|
||||||
.pop()
|
const moduleFile = fs_1.default.readFileSync(modulePath);
|
||||||
.split("/")
|
const moduleB64 = moduleFile.toString("base64");
|
||||||
.slice(1)
|
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${moduleName}', loadNativeModuleTemp('${moduleName}', '${moduleB64}'))`);
|
||||||
.shift();
|
|
||||||
const moduleFile = fs_1.default.readFileSync(modulePath);
|
|
||||||
const moduleB64 = moduleFile.toString("base64");
|
|
||||||
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${moduleName}', loadNativeModuleTemp('${moduleName}', '${moduleB64}'))`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
72
src/index.ts
72
src/index.ts
|
@ -80,54 +80,48 @@ export default function bundleNativeModulesPlugin() {
|
||||||
return edits.push([node.start, node.end]);
|
return edits.push([node.start, node.end]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const matchString of ["require('loady')(__str_aName, __any)"]) {
|
const findLoady = astMatcher("require('loady')(__str_aName, __any)");
|
||||||
const findLoady = astMatcher(matchString);
|
const loadyMatches = findLoady(ast);
|
||||||
const loadyMatches = findLoady(ast);
|
|
||||||
|
|
||||||
if (loadyMatches?.length) {
|
if (loadyMatches?.length) {
|
||||||
for (const match of loadyMatches) {
|
for (const match of loadyMatches) {
|
||||||
if (markEdited(match.node, edits)) {
|
if (markEdited(match.node, edits)) {
|
||||||
const modulePath = loady.resolve(match.match.aName, id);
|
const modulePath = loady.resolve(match.match.aName, id);
|
||||||
const moduleFile = fs.readFileSync(modulePath);
|
const moduleFile = fs.readFileSync(modulePath);
|
||||||
const moduleB64 = moduleFile.toString("base64");
|
const moduleB64 = moduleFile.toString("base64");
|
||||||
magicString.overwrite(
|
magicString.overwrite(
|
||||||
match.node.start,
|
match.node.start,
|
||||||
match.node.end,
|
match.node.end,
|
||||||
`require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`
|
`require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const matchString of [
|
const findNodeBuildGyp = astMatcher("require('node-gyp-build')(__any)");
|
||||||
"require('node-gyp-build')(__any)",
|
const nodeBuildGypMatches = findNodeBuildGyp(ast);
|
||||||
"loadNAPI(__any)",
|
|
||||||
]) {
|
|
||||||
const findNodeBuildGyp = astMatcher(matchString);
|
|
||||||
const nodeBuildGypMatches = findNodeBuildGyp(ast);
|
|
||||||
|
|
||||||
if (nodeBuildGypMatches?.length) {
|
if (nodeBuildGypMatches?.length) {
|
||||||
for (const match of nodeBuildGypMatches) {
|
for (const match of nodeBuildGypMatches) {
|
||||||
if (markEdited(match.node, edits)) {
|
if (markEdited(match.node, edits)) {
|
||||||
const modulePath = nodeGybBuild.path(path.dirname(id));
|
const modulePath = nodeGybBuild.path(path.dirname(id));
|
||||||
const moduleName = modulePath
|
const moduleName = modulePath
|
||||||
.split("node_modules")
|
.split("node_modules")
|
||||||
.pop()
|
.pop()
|
||||||
.split("/")
|
.split("/")
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.shift();
|
.shift();
|
||||||
const moduleFile = fs.readFileSync(modulePath);
|
const moduleFile = fs.readFileSync(modulePath);
|
||||||
const moduleB64 = moduleFile.toString("base64");
|
const moduleB64 = moduleFile.toString("base64");
|
||||||
magicString.overwrite(
|
magicString.overwrite(
|
||||||
match.node.start,
|
match.node.start,
|
||||||
match.node.end,
|
match.node.end,
|
||||||
`require('loady')('${moduleName}', loadNativeModuleTemp('${moduleName}', '${moduleB64}'))`
|
`require('loady')('${moduleName}', loadNativeModuleTemp('${moduleName}', '${moduleB64}'))`
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edits.length === 0) {
|
if (edits.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue