Skip to content

Commit 66893c4

Browse files
authored
refactor(BREAKING): remove entrypoints option (#42)
1 parent 7ff96d9 commit 66893c4

File tree

4 files changed

+20
-42
lines changed

4 files changed

+20
-42
lines changed

src/mod.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ Deno.test("should resolve, load and get graph", async () => {
1111
nodeConditions: undefined, // ensure doesn't error
1212
});
1313
const modFileUrl = import.meta.resolve("./mod.ts");
14-
const { loader, diagnostics } = await workspace.createLoader({
15-
entrypoints: [modFileUrl],
16-
});
14+
const loader = await workspace.createLoader();
15+
const diagnostics = await loader.addEntrypoints([modFileUrl]);
1716
assertEquals(diagnostics.length, 0);
1817
const graph = loader.getGraphUnstable();
1918
assertEquals((graph as any).roots[0], modFileUrl);
@@ -52,9 +51,8 @@ Deno.test("should resolve, load and get graph", async () => {
5251
Deno.test("resolving a jsr specifier should fail with explanatory message", async () => {
5352
const workspace = new Workspace({});
5453
const modFileUrl = import.meta.resolve("./mod.ts");
55-
const { loader, diagnostics } = await workspace.createLoader({
56-
entrypoints: [modFileUrl],
57-
});
54+
const loader = await workspace.createLoader();
55+
const diagnostics = await loader.addEntrypoints([modFileUrl]);
5856
assertEquals(diagnostics.length, 0);
5957
assertRejects(
6058
async () => {

src/mod.ts

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
* const workspace = new Workspace({
1111
* // optional options
1212
* });
13-
* const { loader, diagnostics } = await workspace.createLoader({
14-
* entrypoints: ["./mod.ts"]
15-
* });
13+
* const loader = await workspace.createLoader();
14+
* const diagnostics = await loader.addEntrypoints(["./mod.ts"])
1615
* if (diagnostics.length > 0) {
1716
* throw new Error(diagnostics[0].message);
1817
* }
@@ -68,12 +67,6 @@ export interface WorkspaceOptions {
6867
noTranspile?: boolean;
6968
}
7069

71-
/** Options for loading. */
72-
export interface LoaderOptions {
73-
/** Entrypoints to create the loader for. */
74-
entrypoints: string[];
75-
}
76-
7770
/** File type. */
7871
export enum MediaType {
7972
JavaScript = 0,
@@ -156,20 +149,9 @@ export class Workspace implements Disposable {
156149
}
157150

158151
/** Creates a loader that uses this this workspace. */
159-
async createLoader(
160-
options: LoaderOptions,
161-
): Promise<{ loader: Loader; diagnostics: EntrypointDiagnostic[] }> {
162-
if (this.#debug) {
163-
console.error(
164-
`Creating loader for entrypoints:\n ${
165-
options.entrypoints.join("\n ")
166-
}`,
167-
);
168-
}
152+
async createLoader(): Promise<Loader> {
169153
const wasmLoader = await this.#inner.create_loader();
170-
const loader = new Loader(wasmLoader, this.#debug);
171-
const diagnostics = await loader.addEntrypoints(options.entrypoints);
172-
return { loader, diagnostics };
154+
return new Loader(wasmLoader, this.#debug);
173155
}
174156
}
175157

@@ -202,11 +184,11 @@ export class Loader implements Disposable {
202184
this.#inner.free();
203185
}
204186

205-
/** Adds additional entrypoints to the loader after the fact.
187+
/** Adds entrypoints to the loader.
206188
*
207-
* This may be useful for having a JSR specifier asynchronously
208-
* stored in the internal module graph on the fly, which will allow
209-
* it to be synchronously resolved.
189+
* It's useful to specify entrypoints so that the loader can resolve
190+
* npm: and jsr: specifiers the same way that Deno does when not using
191+
* a lockfile.
210192
*/
211193
async addEntrypoints(
212194
entrypoints: string[],

tests/helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
type LoaderOptions,
32
type LoadResponse,
43
type ModuleLoadResponse,
54
Workspace,
@@ -11,7 +10,7 @@ export * from "@deno/loader";
1110

1211
export async function createLoader(
1312
workspaceOptions: WorkspaceOptions,
14-
loaderOptions: LoaderOptions,
13+
loaderOptions: { entrypoints: string[] },
1514
) {
1615
const { loader, workspace, diagnostics } = await createLoaderWithDiagnostics(
1716
workspaceOptions,
@@ -26,10 +25,11 @@ export async function createLoader(
2625

2726
export async function createLoaderWithDiagnostics(
2827
workspaceOptions: WorkspaceOptions,
29-
loaderOptions: LoaderOptions,
28+
loaderOptions: { entrypoints: string[] },
3029
) {
3130
const workspace = new Workspace(workspaceOptions);
32-
const { loader, diagnostics } = await workspace.createLoader(loaderOptions);
31+
const loader = await workspace.createLoader();
32+
const diagnostics = await loader.addEntrypoints(loaderOptions.entrypoints);
3333
return {
3434
loader,
3535
workspace,

tests/jsx/main.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ ${mainJsxSourceMappingURL}`,
5555

5656
{
5757
const { workspace } = await createWorkspace({ preserveJsx: true });
58-
const { loader: newLoader, diagnostics } = await workspace.createLoader({
59-
entrypoints: [mainJsx, mainTsxUrl],
60-
});
58+
const newLoader = await workspace.createLoader();
59+
const diagnostics = await newLoader.addEntrypoints([mainJsx, mainTsxUrl]);
6160
assertEquals(diagnostics, []);
6261
assertResponseText(
6362
await newLoader.load(mainJsxUrl, RequestedModuleType.Default),
@@ -70,9 +69,8 @@ ${mainJsxSourceMappingURL}`,
7069
}
7170
{
7271
const { workspace } = await createWorkspace({ noTranspile: true });
73-
const { loader: newLoader, diagnostics } = await workspace.createLoader({
74-
entrypoints: [mainJsx, mainTsx],
75-
});
72+
const newLoader = await workspace.createLoader();
73+
const diagnostics = await newLoader.addEntrypoints([mainJsx, mainTsx]);
7674
assertEquals(diagnostics, []);
7775
assertResponseText(
7876
await newLoader.load(mainJsxUrl, RequestedModuleType.Default),

0 commit comments

Comments
 (0)