Compare commits
2 Commits
1f5eb3657e
...
366ffe1ac9
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 366ffe1ac9 | |
Derrick Hammer | d220d9831e |
|
@ -69,33 +69,40 @@ function bundleNativeModulesPlugin() {
|
||||||
// Not edited
|
// Not edited
|
||||||
return edits.push([node.start, node.end]);
|
return edits.push([node.start, node.end]);
|
||||||
}
|
}
|
||||||
const findLoady = (0, ast_matcher_1.default)("require('loady')(__str_aName, __any)");
|
for (const matchString of ["require('loady')(__str_aName, __any)"]) {
|
||||||
const loadyMatches = findLoady(ast);
|
const findLoady = (0, ast_matcher_1.default)(matchString);
|
||||||
if (loadyMatches?.length) {
|
const loadyMatches = findLoady(ast);
|
||||||
for (const match of loadyMatches) {
|
if (loadyMatches?.length) {
|
||||||
if (markEdited(match.node, edits)) {
|
for (const match of loadyMatches) {
|
||||||
const modulePath = loady_1.default.resolve(match.match.aName, id);
|
if (markEdited(match.node, edits)) {
|
||||||
const moduleFile = fs_1.default.readFileSync(modulePath);
|
const modulePath = loady_1.default.resolve(match.match.aName, id);
|
||||||
const moduleB64 = moduleFile.toString("base64");
|
const moduleFile = fs_1.default.readFileSync(modulePath);
|
||||||
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`);
|
const moduleB64 = moduleFile.toString("base64");
|
||||||
|
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${match.match.aName}', loadNativeModuleTemp('${match.match.aName}', '${moduleB64}'))`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const findNodeBuildGyp = (0, ast_matcher_1.default)("require('node-gyp-build')(__any)");
|
for (const matchString of [
|
||||||
const nodeBuildGypMatches = findNodeBuildGyp(ast);
|
"require('node-gyp-build')(__any)",
|
||||||
if (nodeBuildGypMatches?.length) {
|
"loadNAPI(__any)",
|
||||||
for (const match of nodeBuildGypMatches) {
|
]) {
|
||||||
if (markEdited(match.node, edits)) {
|
const findNodeBuildGyp = (0, ast_matcher_1.default)(matchString);
|
||||||
const modulePath = node_gyp_build_1.default.path(path_1.default.dirname(id));
|
const nodeBuildGypMatches = findNodeBuildGyp(ast);
|
||||||
const moduleName = modulePath
|
if (nodeBuildGypMatches?.length) {
|
||||||
.split("node_modules")
|
for (const match of nodeBuildGypMatches) {
|
||||||
.pop()
|
if (markEdited(match.node, edits)) {
|
||||||
.split("/")
|
const modulePath = node_gyp_build_1.default.path(path_1.default.dirname(id));
|
||||||
.slice(1)
|
const moduleName = modulePath
|
||||||
.shift();
|
.split("node_modules")
|
||||||
const moduleFile = fs_1.default.readFileSync(modulePath);
|
.pop()
|
||||||
const moduleB64 = moduleFile.toString("base64");
|
.split("/")
|
||||||
magicString.overwrite(match.node.start, match.node.end, `require('loady')('${moduleName}', loadNativeModuleTemp('${moduleName}', '${moduleB64}'))`);
|
.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}'))`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
72
src/index.ts
72
src/index.ts
|
@ -80,48 +80,54 @@ export default function bundleNativeModulesPlugin() {
|
||||||
return edits.push([node.start, node.end]);
|
return edits.push([node.start, node.end]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const findLoady = astMatcher("require('loady')(__str_aName, __any)");
|
for (const matchString of ["require('loady')(__str_aName, __any)"]) {
|
||||||
const loadyMatches = findLoady(ast);
|
const findLoady = astMatcher(matchString);
|
||||||
|
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}'))`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const findNodeBuildGyp = astMatcher("require('node-gyp-build')(__any)");
|
for (const matchString of [
|
||||||
const nodeBuildGypMatches = findNodeBuildGyp(ast);
|
"require('node-gyp-build')(__any)",
|
||||||
|
"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