mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 05:33:54 +01:00
imports are more flexible
This commit is contained in:
parent
16c51e8e8e
commit
ed86577d6c
14
dist/vendor.bundle.js
vendored
14
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -2,6 +2,7 @@ import { makeRuntimeRejectMsg } from "./NetscriptEvaluator";
|
||||
import { ScriptUrl } from "./Script/ScriptUrl";
|
||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||
import { Script } from "./Script/Script";
|
||||
import { areImportsEquals } from "./Terminal/DirectoryHelpers";
|
||||
|
||||
export const BlobsMap: { [key: string]: string } = {};
|
||||
|
||||
@ -117,11 +118,11 @@ function _getScriptUrls(script: Script, scripts: Script[], seen: Script[]): Scri
|
||||
let transformedCode = script.code.replace(
|
||||
/((?:from|import)\s+(?:'|"))(?:\.\/)?([^'"]+)('|")/g,
|
||||
(unmodified, prefix, filename, suffix) => {
|
||||
const isAllowedImport = scripts.some((s) => s.filename == filename);
|
||||
const isAllowedImport = scripts.some((s) => areImportsEquals(s.filename, filename));
|
||||
if (!isAllowedImport) return unmodified;
|
||||
|
||||
// Find the corresponding script.
|
||||
const [importedScript] = scripts.filter((s) => s.filename == filename);
|
||||
const [importedScript] = scripts.filter((s) => areImportsEquals(s.filename, filename));
|
||||
|
||||
// Try to get a URL for the requested script and its dependencies.
|
||||
const urls = _getScriptUrls(importedScript, scripts, seen);
|
||||
|
@ -13,6 +13,7 @@ import { RamCalculationErrorCode } from "./RamCalculationErrorCodes";
|
||||
import { RamCosts, RamCostConstants } from "../Netscript/RamCostGenerator";
|
||||
import { Script } from "../Script/Script";
|
||||
import { WorkerScript } from "../Netscript/WorkerScript";
|
||||
import { areImportsEquals } from "../Terminal/DirectoryHelpers";
|
||||
|
||||
// These special strings are used to reference the presence of a given logical
|
||||
// construct within a user script.
|
||||
@ -106,8 +107,9 @@ async function parseOnlyRamCalculate(
|
||||
let script = null;
|
||||
const fn = nextModule.startsWith("./") ? nextModule.slice(2) : nextModule;
|
||||
for (const s of otherScripts) {
|
||||
if (s.filename === fn) {
|
||||
if (areImportsEquals(s.filename, fn)) {
|
||||
script = s;
|
||||
console.log(`${s.filename} ${fn}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ export function isValidFilename(filename: string): boolean {
|
||||
* Checks whether a string is a valid directory name. Only used for the directory itself,
|
||||
* not an entire path
|
||||
*/
|
||||
export function isValidDirectoryName(name: string): boolean {
|
||||
export function isValidDirectoryName(name: string): boolean {
|
||||
// Allows alphanumerics, hyphens, underscores, and percentage signs.
|
||||
// Name can begin with a single period, but otherwise cannot have any
|
||||
const regex = /^.?[a-zA-Z0-9_-]+$/;
|
||||
@ -310,3 +310,9 @@ export function areFilesEqual(f0: string, f1: string): boolean {
|
||||
if (!f1.startsWith("/")) f1 = "/" + f1;
|
||||
return f0 === f1;
|
||||
}
|
||||
|
||||
export function areImportsEquals(f0: string, f1: string): boolean {
|
||||
if (!f0.endsWith(".ns") && !f0.endsWith(".js")) f0 = f0 + ".js";
|
||||
if (!f1.endsWith(".ns") && !f1.endsWith(".js")) f1 = f1 + ".js";
|
||||
return areFilesEqual(f0, f1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user