Compare commits

..

No commits in common. "366ffe1ac9c3a61cc98212f8bb7d9e59b02a16f4" and "1f5eb3657e6699067003be2e8ff146aef0115355" have entirely different histories.

2 changed files with 57 additions and 70 deletions

55
dist/index.js vendored
View File

@ -69,40 +69,33 @@ function bundleNativeModulesPlugin() {
// Not edited
return edits.push([node.start, node.end]);
}
for (const matchString of ["require('loady')(__str_aName, __any)"]) {
const findLoady = (0, ast_matcher_1.default)(matchString);
const loadyMatches = findLoady(ast);
if (loadyMatches?.length) {
for (const match of loadyMatches) {
if (markEdited(match.node, edits)) {
const modulePath = loady_1.default.resolve(match.match.aName, id);
const moduleFile = fs_1.default.readFileSync(modulePath);
const moduleB64 = moduleFile.toString("base64");
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`);
}
const findLoady = (0, ast_matcher_1.default)("require('loady')(__str_aName, __any)");
const loadyMatches = findLoady(ast);
if (loadyMatches?.length) {
for (const match of loadyMatches) {
if (markEdited(match.node, edits)) {
const modulePath = loady_1.default.resolve(match.match.aName, id);
const moduleFile = fs_1.default.readFileSync(modulePath);
const moduleB64 = moduleFile.toString("base64");
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`);
}
}
}
for (const matchString of [
"require('node-gyp-build')(__any)",
"loadNAPI(__any)",
]) {
const findNodeBuildGyp = (0, ast_matcher_1.default)(matchString);
const nodeBuildGypMatches = findNodeBuildGyp(ast);
if (nodeBuildGypMatches?.length) {
for (const match of nodeBuildGypMatches) {
if (markEdited(match.node, edits)) {
const modulePath = node_gyp_build_1.default.path(path_1.default.dirname(id));
const moduleName = modulePath
.split("node_modules")
.pop()
.split("/")
.slice(1)
.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}'))`);
}
const findNodeBuildGyp = (0, ast_matcher_1.default)("require('node-gyp-build')(__any)");
const nodeBuildGypMatches = findNodeBuildGyp(ast);
if (nodeBuildGypMatches?.length) {
for (const match of nodeBuildGypMatches) {
if (markEdited(match.node, edits)) {
const modulePath = node_gyp_build_1.default.path(path_1.default.dirname(id));
const moduleName = modulePath
.split("node_modules")
.pop()
.split("/")
.slice(1)
.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}'))`);
}
}
}

View File

@ -80,54 +80,48 @@ export default function bundleNativeModulesPlugin() {
return edits.push([node.start, node.end]);
}
for (const matchString of ["require('loady')(__str_aName, __any)"]) {
const findLoady = astMatcher(matchString);
const loadyMatches = findLoady(ast);
const findLoady = astMatcher("require('loady')(__str_aName, __any)");
const loadyMatches = findLoady(ast);
if (loadyMatches?.length) {
for (const match of loadyMatches) {
if (markEdited(match.node, edits)) {
const modulePath = loady.resolve(match.match.aName, id);
const moduleFile = fs.readFileSync(modulePath);
const moduleB64 = moduleFile.toString("base64");
magicString.overwrite(
match.node.start,
match.node.end,
`require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`
);
}
if (loadyMatches?.length) {
for (const match of loadyMatches) {
if (markEdited(match.node, edits)) {
const modulePath = loady.resolve(match.match.aName, id);
const moduleFile = fs.readFileSync(modulePath);
const moduleB64 = moduleFile.toString("base64");
magicString.overwrite(
match.node.start,
match.node.end,
`require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`
);
}
}
}
for (const matchString of [
"require('node-gyp-build')(__any)",
"loadNAPI(__any)",
]) {
const findNodeBuildGyp = astMatcher(matchString);
const nodeBuildGypMatches = findNodeBuildGyp(ast);
const findNodeBuildGyp = astMatcher("require('node-gyp-build')(__any)");
const nodeBuildGypMatches = findNodeBuildGyp(ast);
if (nodeBuildGypMatches?.length) {
for (const match of nodeBuildGypMatches) {
if (markEdited(match.node, edits)) {
const modulePath = nodeGybBuild.path(path.dirname(id));
const moduleName = modulePath
.split("node_modules")
.pop()
.split("/")
.slice(1)
.shift();
const moduleFile = fs.readFileSync(modulePath);
const moduleB64 = moduleFile.toString("base64");
magicString.overwrite(
match.node.start,
match.node.end,
`require('loady')('${moduleName}', loadNativeModuleTemp('${moduleName}', '${moduleB64}'))`
);
}
if (nodeBuildGypMatches?.length) {
for (const match of nodeBuildGypMatches) {
if (markEdited(match.node, edits)) {
const modulePath = nodeGybBuild.path(path.dirname(id));
const moduleName = modulePath
.split("node_modules")
.pop()
.split("/")
.slice(1)
.shift();
const moduleFile = fs.readFileSync(modulePath);
const moduleB64 = moduleFile.toString("base64");
magicString.overwrite(
match.node.start,
match.node.end,
`require('loady')('${moduleName}', loadNativeModuleTemp('${moduleName}', '${moduleB64}'))`
);
}
}
}
if (edits.length === 0) {
return null;
}