Skip to content

provide access to inner graph #28

@nestarz

Description

@nestarz

Accessing the graph constructed in the loader here

graph: ModuleGraph,
is an expensive operation and it would be better to let users not recreate it using @deno/graph library. This would let bundler plugins or libraries to get the module graph to perform prebuild operations.

For now we need to do:

  const workspace = new Workspace({
    cachedOnly: true,
    preserveJsx: true,
    noTranspile: true,
    configPath: configPath,
  });
  console.time("create_loader");
  const loader = await workspace.createLoader({
    entrypoints: [config.entrypoint.href, ...bootstrapModules],
  });
  console.timeEnd("create_loader");

  const cache = createCache();
  console.time("create_graph");
  const graph = await createGraph(
    [config.entrypoint.href, ...bootstrapModules],
    {
      kind: "codeOnly",
      load: cache.load,
      cacheInfo: cache.cacheInfo,
      resolve: (s, r) => {
        try {
          try {
            return loader.resolve(s, r, ResolutionMode.Import);
          } catch {
            return loader.resolve(s, r, ResolutionMode.Require);
          }
        } catch (error) {
          console.log(`Unable to resolve: ${s} from ${r}`);
          throw error;
        }
      },
    },
  );
  console.timeEnd("create_graph");

which is redundant work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions