Skip to content

Commit

Permalink
Disable importConditionDefaultExport for now
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed May 2, 2023
1 parent 958130b commit 5380890
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-cheetahs-stare.md
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": patch
---

Disable specifying `importConditionDefaultExport` because it doesn't work correctly in `"moduleResoltion": "bundler"`, `@preconstruct/cli@2.6.0` is npm deprecated, `importConditionDefaultExport` will come back in the future.
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/dev.ts
Expand Up @@ -418,7 +418,7 @@ test(".d.ts file with default export", async () => {
`);
});

test("with default", async () => {
test.skip("with default", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "@mjs-proxy/repo",
Expand Down
26 changes: 13 additions & 13 deletions packages/cli/src/__tests__/validate.ts
Expand Up @@ -729,7 +729,7 @@ describe("exports field config", () => {
`[Error: the "preconstruct.exports" field contains an unknown key "something"]`
);
});
test("invalid importConditionDefaultExport", async () => {
test.skip("invalid importConditionDefaultExport", async () => {
const tmpPath = await exportsFieldConfigTestDir({
importConditionDefaultExport: "something",
});
Expand All @@ -745,14 +745,14 @@ describe("exports field config", () => {
{ envConditions: [] },
{ envConditions: [], extra: {} },
{ extra: {} },
{ envConditions: [], importConditionDefaultExport: "namespace" },
{
envConditions: [],
extra: {},
importConditionDefaultExport: "namespace",
},
{ extra: {}, importConditionDefaultExport: "namespace" },
{ importConditionDefaultExport: "namespace" },
// { envConditions: [], importConditionDefaultExport: "namespace" },
// {
// envConditions: [],
// extra: {},
// importConditionDefaultExport: "namespace",
// },
// { extra: {}, importConditionDefaultExport: "namespace" },
// { importConditionDefaultExport: "namespace" },
true,
];
for (const config of configsEquivalentToTrue) {
Expand Down Expand Up @@ -781,7 +781,7 @@ describe("exports field config", () => {
});
}
});
test('{ "importConditionDefaultExport": "default" }', async () => {
test.skip('{ "importConditionDefaultExport": "default" }', async () => {
const tmpPath = await testdir({
"package.json": JSON.stringify({
name: "pkg-a",
Expand Down Expand Up @@ -877,14 +877,14 @@ describe("project level exports field config", () => {
importConditionDefaultExport: "something",
});
await expect(validate(tmpPath)).rejects.toMatchInlineSnapshot(
`[Error: the "preconstruct.exports.importConditionDefaultExport" field must be set to "default" or "namespace" if it is present]`
`[Error: the "preconstruct.exports.importConditionDefaultExport" is currently broken and disabled, it will be re-enabled with a different implemtation in a future version]`
);
});
});
describe("true", () => {
const configsEquivalentToTrue = [
{},
{ importConditionDefaultExport: "namespace" },
// { importConditionDefaultExport: "namespace" },
true,
];
for (const config of configsEquivalentToTrue) {
Expand All @@ -894,7 +894,7 @@ describe("project level exports field config", () => {
});
}
});
test('{ "importConditionDefaultExport": "default" }', async () => {
test.skip('{ "importConditionDefaultExport": "default" }', async () => {
const tmpPath = await testdir({
"package.json": JSON.stringify({
name: "repo",
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/build/__tests__/build.ts
Expand Up @@ -918,7 +918,7 @@ test("self import", async () => {
`);
});

test("correct default export using mjs and dmts proxies", async () => {
test.skip("correct default export using mjs and dmts proxies", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "@mjs-proxy/repo",
Expand Down Expand Up @@ -1135,7 +1135,7 @@ test("correct default export using mjs and dmts proxies", async () => {
expect(node.stderr.toString("utf8")).toMatchInlineSnapshot(`""`);
});

test("importing a package via dynamic import from another package provides the right types", async () => {
test.skip("importing a package via dynamic import from another package provides the right types", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "@mjs-proxy/repo",
Expand Down Expand Up @@ -1272,7 +1272,7 @@ test("importing a package via dynamic import from another package provides the r
`);
});

test("importing another package via dynamic import and exporting the namespace produces a typescript error because the type cannot be named", async () => {
test.skip("importing another package via dynamic import and exporting the namespace produces a typescript error because the type cannot be named", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "@mjs-proxy/repo",
Expand Down Expand Up @@ -1349,7 +1349,7 @@ test("importing another package via dynamic import and exporting the namespace p
`);
});

test("importing another package via dynamic import and exporting something that requires importing a type from the other package works", async () => {
test.skip("importing another package via dynamic import and exporting something that requires importing a type from the other package works", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "@mjs-proxy/repo",
Expand Down Expand Up @@ -1459,7 +1459,7 @@ test("importing another package via dynamic import and exporting something that
`);
});

test("no __esModule when reexporting namespace with mjs proxy", async () => {
test.skip("no __esModule when reexporting namespace with mjs proxy", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "@mjs-proxy-no-__esmodule/repo",
Expand Down Expand Up @@ -1582,7 +1582,7 @@ test("no __esModule when reexporting namespace with mjs proxy", async () => {
expect(node.stderr.toString("utf8")).toMatchInlineSnapshot(`""`);
});

test("export * from external", async () => {
test.skip("export * from external", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "repo",
Expand Down Expand Up @@ -1746,7 +1746,7 @@ test("export * from external", async () => {
expect(stderr.toString("utf8")).toMatchInlineSnapshot(`""`);
});

test("type only export imported in .mts", async () => {
test.skip("type only export imported in .mts", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "repo",
Expand Down Expand Up @@ -1839,7 +1839,7 @@ test("type only export imported in .mts", async () => {
expect(stderr.toString("utf8")).toMatchInlineSnapshot(`""`);
});

test("importConditionDefaultExport: default with use client", async () => {
test.skip("importConditionDefaultExport: default with use client", async () => {
let dir = await testdir({
"package.json": JSON.stringify({
name: "pkg-a",
Expand Down
13 changes: 5 additions & 8 deletions packages/cli/src/package.ts
Expand Up @@ -17,6 +17,7 @@ import {
setFieldInOrder,
DistFilenameStrategy,
MinimalEntrypoint,
parseImportConditionDefaultExportOption,
} from "./utils";
import normalizePath from "normalize-path";

Expand Down Expand Up @@ -406,14 +407,10 @@ function parseExportsFieldConfig(
);
}
} else if (key === "importConditionDefaultExport") {
if (value === "default" || value === "namespace") {
parsedConfig.importConditionDefaultExport = value;
} else {
throw new FatalError(
'the "preconstruct.exports.importConditionDefaultExport" field must be set to "default" or "namespace" if it is present',
name
);
}
parsedConfig.importConditionDefaultExport = parseImportConditionDefaultExportOption(
value,
name
);
} else {
throw new FatalError(
`the "preconstruct.exports" field contains an unknown key "${key}"`,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/project.ts
Expand Up @@ -6,7 +6,7 @@ import { Item } from "./item";
import { Package } from "./package";
import { validateIncludedFiles } from "./validate-included-files";
import { FatalError } from "./errors";
import { JSONValue, parseimportConditionDefaultExportOption } from "./utils";
import { JSONValue, parseImportConditionDefaultExportOption } from "./utils";

const allSettled = (promises: Promise<any>[]) =>
Promise.all(
Expand Down Expand Up @@ -162,7 +162,7 @@ export class Project extends Item<{
}
for (const [key, val] of Object.entries(exportsFieldConfig)) {
if (key === "importConditionDefaultExport") {
importConditionDefaultExport = parseimportConditionDefaultExportOption(
importConditionDefaultExport = parseImportConditionDefaultExportOption(
val,
this.name
);
Expand Down
16 changes: 10 additions & 6 deletions packages/cli/src/utils.ts
Expand Up @@ -280,15 +280,19 @@ export type JSONValue =
| Array<JSONValue>
| { [key: string]: JSONValue | undefined };

export function parseimportConditionDefaultExportOption(
export function parseImportConditionDefaultExportOption(
value: unknown,
name: string
) {
if (value === "default" || value === "namespace") {
return value;
}
): "default" | "namespace" {
throw new FatalError(
'the "preconstruct.exports.importConditionDefaultExport" field must be set to "default" or "namespace" if it is present',
`the "preconstruct.exports.importConditionDefaultExport" is currently broken and disabled, it will be re-enabled with a different implemtation in a future version`,
name
);
// if (value === "default" || value === "namespace") {
// return value;
// }
// throw new FatalError(
// 'the "preconstruct.exports.importConditionDefaultExport" field must be set to "default" or "namespace" if it is present',
// name
// );
}

0 comments on commit 5380890

Please sign in to comment.