Skip to content

Commit

Permalink
fix: provide parentUrl to resolveLatestTarget (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Oct 15, 2024
1 parent 9fea38f commit bbd7930
Show file tree
Hide file tree
Showing 7 changed files with 789 additions and 457 deletions.
1,176 changes: 751 additions & 425 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
},
"devDependencies": {
"@jspm/core": "^2.0.1",
"@swc/cli": "^0.1.61",
"@swc/core": "^1.3.35",
"@swc/cli": "^0.1.65",
"@swc/core": "^1.7.35",
"@types/vscode": "^1.75.1",
"@vscode/test-electron": "^2.2.3",
"chalk": "^4.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/common/str.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class Replacer {
const [wsMatch] = this.source.slice(endIndex).match(trimWs) ?? [];
this.source =
this.source.slice(0, endIndex) +
this.source.slice(endIndex + wsMatch?.length ?? 0);
addOffset(this.offsetTable, end, -wsMatch?.length ?? 0);
this.source.slice(endIndex + (wsMatch?.length ?? 0));
addOffset(this.offsetTable, end, -(wsMatch?.length ?? 0));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/providers/jspm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let cdnUrl = "https://ga.jspm.io/";
const systemCdnUrl = "https://ga.system.jspm.io/";
const apiUrl = "https://api.jspm.io/";

const BUILD_POLL_TIME = 5 * 60 * 1000;
const BUILD_POLL_TIME = 60 * 1000;
const BUILD_POLL_INTERVAL = 5 * 1000;

interface JspmCache {
Expand Down Expand Up @@ -150,7 +150,7 @@ async function ensureBuild(resolver: Resolver, pkg: ExactPackage, fetchOpts: any

if (Date.now() - startTime >= BUILD_POLL_TIME)
throw new JspmError(
`Timed out waiting for the build of ${fullName} to be ready on the JSPM CDN. Try again later, or post a JSPM project issue if the issue persists.`
`Timed out waiting for the build of ${fullName} to be ready on the JSPM CDN. Try again later, or post a jspm.io project issue at https://github.com/jspm/project if the problem persists.`
);
}
})();
Expand Down
8 changes: 4 additions & 4 deletions src/trace/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class Resolver {
const subpath = "./" + url.slice(pkgUrl.length);
if (subpath in pcfg.browser) {
const target = pcfg.browser[subpath];
if (target === false) return this.resolveEmpty(parentIsCjs, url);
if (target === false) return this.resolveEmpty(parentIsCjs, url, pkgUrl);
if (!target.startsWith("./"))
throw new Error(
`TODO: External browser map for ${subpath} to ${target} in ${url}`
Expand Down Expand Up @@ -718,7 +718,7 @@ export class Resolver {
return null;
}

async resolveEmpty(cjsEnv: boolean, originalSpecifier: string, parentUrl?: URL) {
async resolveEmpty(cjsEnv: boolean, originalSpecifier: string, parentUrl: string) {
const stdlibTarget = {
registry: "npm",
name: "@jspm/core",
Expand All @@ -729,7 +729,7 @@ export class Resolver {
const pkg = await this.resolveLatestTarget(
stdlibTarget,
provider,
parentUrl?.href
parentUrl
);
return this.resolveExport(
await this.pkgToUrl(pkg, provider),
Expand All @@ -748,7 +748,7 @@ export class Resolver {
cjsEnv: boolean,
parentIsCjs: boolean,
originalSpecifier: string,
parentUrl?: URL
parentUrl?: string
): Promise<string> {
const env = cjsEnv ? this.cjsEnv : this.env;
const pcfg = (await this.getPackageConfig(pkgUrl)) || {};
Expand Down
4 changes: 2 additions & 2 deletions src/trace/tracemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export default class TraceMap {
cjsEnv,
parentIsCjs,
specifier,
new URL(parentUrl)
parentUrl
)
);
this.log(
Expand Down Expand Up @@ -566,7 +566,7 @@ export default class TraceMap {
cjsEnv,
parentIsCjs,
specifier,
new URL(parentUrl)
parentUrl
)
);
this.log(
Expand Down
46 changes: 26 additions & 20 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"scopes": {
"../": {
"#fetch": "../dist/fetch-native.js",
"@babel/core": "https://ga.jspm.io/npm:@babel/[email protected].2/lib/index.js",
"@babel/plugin-syntax-import-attributes": "https://ga.jspm.io/npm:@babel/[email protected].6/lib/index.js",
"@babel/core": "https://ga.jspm.io/npm:@babel/[email protected].8/lib/index.js",
"@babel/plugin-syntax-import-attributes": "https://ga.jspm.io/npm:@babel/[email protected].7/lib/index.js",
"@babel/preset-typescript": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@jspm/import-map": "https://ga.jspm.io/npm:@jspm/[email protected]/dist/map.js",
"es-module-lexer": "https://ga.jspm.io/npm:[email protected]/dist/lexer.js",
Expand All @@ -23,40 +23,40 @@
"url": "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/url.js"
},
"https://ga.jspm.io/": {
"#lib/config/files/index.js": "https://ga.jspm.io/npm:@babel/[email protected].2/lib/config/files/index-browser.js",
"#lib/config/resolve-targets.js": "https://ga.jspm.io/npm:@babel/[email protected].2/lib/config/resolve-targets-browser.js",
"#lib/transform-file.js": "https://ga.jspm.io/npm:@babel/[email protected].2/lib/transform-file-browser.js",
"#lib/config/files/index.js": "https://ga.jspm.io/npm:@babel/[email protected].8/lib/config/files/index-browser.js",
"#lib/config/resolve-targets.js": "https://ga.jspm.io/npm:@babel/[email protected].8/lib/config/resolve-targets-browser.js",
"#lib/transform-file.js": "https://ga.jspm.io/npm:@babel/[email protected].8/lib/transform-file-browser.js",
"#node.js": "https://ga.jspm.io/npm:[email protected]/browser.js",
"@ampproject/remapping": "https://ga.jspm.io/npm:@ampproject/[email protected]/dist/remapping.umd.js",
"@babel/code-frame": "https://ga.jspm.io/npm:@babel/code-frame@7.24.7/lib/index.js",
"@babel/code-frame": "https://ga.jspm.io/npm:@babel/code-frame@7.25.7/lib/index.js",
"@babel/compat-data/native-modules": "https://ga.jspm.io/npm:@babel/[email protected]/native-modules.js",
"@babel/compat-data/plugins": "https://ga.jspm.io/npm:@babel/[email protected]/plugins.js",
"@babel/core": "https://ga.jspm.io/npm:@babel/[email protected].2/lib/index.js",
"@babel/core": "https://ga.jspm.io/npm:@babel/[email protected].8/lib/index.js",
"@babel/generator": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/helper-annotate-as-pure": "https://ga.jspm.io/npm:@babel/helper-annotate-as-pure@7.24.7/lib/index.js",
"@babel/helper-annotate-as-pure": "https://ga.jspm.io/npm:@babel/helper-annotate-as-pure@7.25.7/lib/index.js",
"@babel/helper-compilation-targets": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/helper-create-class-features-plugin": "https://ga.jspm.io/npm:@babel/[email protected].4/lib/index.js",
"@babel/helper-member-expression-to-functions": "https://ga.jspm.io/npm:@babel/helper-member-expression-to-functions@7.24.8/lib/index.js",
"@babel/helper-create-class-features-plugin": "https://ga.jspm.io/npm:@babel/[email protected].7/lib/index.js",
"@babel/helper-member-expression-to-functions": "https://ga.jspm.io/npm:@babel/helper-member-expression-to-functions@7.25.7/lib/index.js",
"@babel/helper-module-imports": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/helper-module-transforms": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/helper-optimise-call-expression": "https://ga.jspm.io/npm:@babel/helper-optimise-call-expression@7.24.7/lib/index.js",
"@babel/helper-plugin-utils": "https://ga.jspm.io/npm:@babel/helper-plugin-utils@7.24.8/lib/index.js",
"@babel/helper-optimise-call-expression": "https://ga.jspm.io/npm:@babel/helper-optimise-call-expression@7.25.7/lib/index.js",
"@babel/helper-plugin-utils": "https://ga.jspm.io/npm:@babel/helper-plugin-utils@7.25.7/lib/index.js",
"@babel/helper-replace-supers": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/helper-simple-access": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/helper-skip-transparent-expression-wrappers": "https://ga.jspm.io/npm:@babel/helper-skip-transparent-expression-wrappers@7.24.7/lib/index.js",
"@babel/helper-string-parser": "https://ga.jspm.io/npm:@babel/helper-string-parser@7.24.8/lib/index.js",
"@babel/helper-validator-identifier": "https://ga.jspm.io/npm:@babel/helper-validator-identifier@7.24.7/lib/index.js",
"@babel/helper-skip-transparent-expression-wrappers": "https://ga.jspm.io/npm:@babel/helper-skip-transparent-expression-wrappers@7.25.7/lib/index.js",
"@babel/helper-string-parser": "https://ga.jspm.io/npm:@babel/helper-string-parser@7.25.7/lib/index.js",
"@babel/helper-validator-identifier": "https://ga.jspm.io/npm:@babel/helper-validator-identifier@7.25.7/lib/index.js",
"@babel/helper-validator-option": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/helpers": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/highlight": "https://ga.jspm.io/npm:@babel/highlight@7.24.7/lib/index.js",
"@babel/parser": "https://ga.jspm.io/npm:@babel/[email protected].6/lib/index.js",
"@babel/highlight": "https://ga.jspm.io/npm:@babel/highlight@7.25.7/lib/index.js",
"@babel/parser": "https://ga.jspm.io/npm:@babel/[email protected].8/lib/index.js",
"@babel/plugin-syntax-jsx": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/plugin-syntax-typescript": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/plugin-transform-modules-commonjs": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/plugin-transform-typescript": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/template": "https://ga.jspm.io/npm:@babel/[email protected].0/lib/index.js",
"@babel/template": "https://ga.jspm.io/npm:@babel/[email protected].7/lib/index.js",
"@babel/traverse": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js",
"@babel/types": "https://ga.jspm.io/npm:@babel/[email protected].6/lib/index.js",
"@babel/types": "https://ga.jspm.io/npm:@babel/[email protected].8/lib/index.js",
"@jridgewell/gen-mapping": "https://ga.jspm.io/npm:@jridgewell/[email protected]/dist/gen-mapping.umd.js",
"@jridgewell/resolve-uri": "https://ga.jspm.io/npm:@jridgewell/[email protected]/dist/resolve-uri.umd.js",
"@jridgewell/set-array": "https://ga.jspm.io/npm:@jridgewell/[email protected]/dist/set-array.umd.js",
Expand All @@ -71,7 +71,7 @@
"color-name": "https://ga.jspm.io/npm:[email protected]/index.js",
"convert-source-map": "https://ga.jspm.io/npm:[email protected]/index.js",
"debug": "https://ga.jspm.io/npm:[email protected]/src/browser.js",
"electron-to-chromium/versions": "https://ga.jspm.io/npm:[email protected].29/versions.js",
"electron-to-chromium/versions": "https://ga.jspm.io/npm:[email protected].37/versions.js",
"escape-string-regexp": "https://ga.jspm.io/npm:[email protected]/index.js",
"fs": "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/fs.js",
"gensync": "https://ga.jspm.io/npm:[email protected]/index.js",
Expand All @@ -89,6 +89,12 @@
"supports-color": "https://ga.jspm.io/npm:[email protected]/browser.js",
"to-fast-properties": "https://ga.jspm.io/npm:[email protected]/index.js",
"yallist": "https://ga.jspm.io/npm:[email protected]/yallist.js"
},
"https://ga.jspm.io/npm:@babel/[email protected]/": {
"@babel/helper-member-expression-to-functions": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js"
},
"https://ga.jspm.io/npm:@babel/[email protected]/": {
"@babel/helper-skip-transparent-expression-wrappers": "https://ga.jspm.io/npm:@babel/[email protected]/lib/index.js"
}
}
}
Expand Down

0 comments on commit bbd7930

Please sign in to comment.