Skip to content

Commit

Permalink
fix(chaching): explicit import result requests (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
petermasking authored Feb 13, 2024
1 parent 1551fde commit 40eadc9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
3 changes: 2 additions & 1 deletion packages/caching/src/building/utils/ImportRewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export default class ImportRewriter
}

const members = this.#rewriteImportMembers(dependency);
const extractDefault = this.#mustUseAs(dependency) ? 'true' : 'false';

return `const ${members} = await __import("${from}", "${scope}");`;
return `const ${members} = await __import("${from}", "${scope}", ${extractDefault});`;
}

#rewriteImportFrom(dependency: ReflectionImport, filename: string): string
Expand Down
16 changes: 8 additions & 8 deletions packages/caching/test/_fixtures/CacheFiles.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const segment = new Segment("product")
\t)`;

const CREATE_ORDER_LOCAL =
`const { Order, OrderLine } = await __import("./order/models.js", "application");
`const { Order, OrderLine } = await __import("./order/models.js", "application", false);
export default async function createOrder(items)
{
Expand All @@ -56,9 +56,9 @@ const CREATE_ORDER_REMOTE =
}`;

const STORE_ORDER_LOCAL =
`const mysql = await __import("mysql", "runtime");
const createId = await __import("uuid", "runtime");
const { Order } = await __import("./order/models.js", "application");
`const mysql = await __import("mysql", "runtime", true);
const createId = await __import("uuid", "runtime", true);
const { Order } = await __import("./order/models.js", "application", false);
export async function v0_0_0(order)
{
Expand Down Expand Up @@ -87,8 +87,8 @@ Order.source = "./order/models.js";
OrderLine.source = "./order/models.js";`;

const GET_PRODUCTS_LOCAL =
`const mongodb = await __import("mongodb", "runtime");
const { Product } = await __import("./product/models.js", "application");
`const mongodb = await __import("mongodb", "runtime", true);
const { Product } = await __import("./product/models.js", "application", false);
export default async function getProducts(id)
{
Expand All @@ -115,8 +115,8 @@ export async function searchProducts({ query , sort }) {
}`;

const GET_PRODUCTS_LOCAL_V1 =
`const mongodb = await __import("mongodb", "runtime");
const { Product } = await __import("./product/models.js", "application");
`const mongodb = await __import("mongodb", "runtime", true);
const { Product } = await __import("./product/models.js", "application", false);
export default async function getProducts(id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { component1, component2 } from '../path/to/components.js';

const APPLICATION_IMPORTS_RESULT =
`await __import("./components/path/to/file.js", "application");
const component = await __import("./components/path/to/component.js", "application");
const { component1, component2 } = await __import("./path/to/components.js", "application");
const component = await __import("./components/path/to/component.js", "application", true);
const { component1, component2 } = await __import("./path/to/components.js", "application", false);
`;

const RUNTIME_IMPORTS =
Expand All @@ -21,14 +21,14 @@ import { component1, component2 } from 'https';

const RUNTIME_IMPORTS_RESULT =
`await __import("polyfills", "runtime");
const fs = await __import("fs", "runtime");
const component = await __import("http", "runtime");
const { component1, component2 } = await __import("https", "runtime");
const fs = await __import("fs", "runtime", true);
const component = await __import("http", "runtime", true);
const { component1, component2 } = await __import("https", "runtime", false);
`;

const IMPORT_WITHOUT_SEMICOLON = `import { runProcedure } from 'jitar'`;

const IMPORT_WITHOUT_SEMICOLON_RESULT = `const { runProcedure } = await __import("jitar", "runtime");`;
const IMPORT_WITHOUT_SEMICOLON_RESULT = `const { runProcedure } = await __import("jitar", "runtime", false);`;

// Without .js extension
const MIXED_IMPORTS =
Expand All @@ -39,10 +39,10 @@ import main, { some as other } from 'library';
`;

const MIXED_IMPORTS_RESULT =
`const component = await __import("./components/path/to/component.js", "application");
const os = await __import("os", "runtime");
const { runProcedure } = await __import("jitar", "runtime");
const { default : main, some : other } = await __import("library", "runtime");
`const component = await __import("./components/path/to/component.js", "application", true);
const os = await __import("os", "runtime", true);
const { runProcedure } = await __import("jitar", "runtime", false);
const { default : main, some : other } = await __import("library", "runtime", false);
`;

const DYNAMIC_IMPORTS =
Expand All @@ -51,7 +51,7 @@ const os = await import('os');
`;

const DYNAMIC_IMPORTS_RESULT =
`const component = await __import("./components/path/to/component.js", "application");
`const component = await __import("./components/path/to/component.js", "application", true);
const os = await import('os');
`;

Expand All @@ -64,11 +64,11 @@ import { runProcedure } from 'jitar';
`;

const IMPORTS_AND_CONTENT_RESULT =
`const os = await __import("os", "runtime");
`const os = await __import("os", "runtime", true);
export default function test() {}
const { runProcedure } = await __import("jitar", "runtime");
const { runProcedure } = await __import("jitar", "runtime", false);
`;

const INPUTS =
Expand Down

0 comments on commit 40eadc9

Please sign in to comment.