Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support import.meta.url in preconstruct dev #524

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/shaggy-comics-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@preconstruct/cli": patch
"@preconstruct/hook": patch
---

Support `import.meta.url` in `preconstruct dev`
26 changes: 26 additions & 0 deletions packages/cli/src/__tests__/dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import spawn from "spawndamnit";
import path from "path";
import * as fs from "fs-extra";
import { pathToFileURL } from "url";
import * as realFs from "fs";
import { getFiles, js, testdir, ts, typescriptFixture } from "../../test-utils";
import dev from "../dev";
Expand Down Expand Up @@ -368,3 +369,28 @@ test("flow and .d.ts", async () => {
export const x = "hello";
`);
});

test("import.meta.url", async () => {
let tmpPath = await testdir({
"package.json": JSON.stringify({
name: "pkg",
main: "dist/pkg.cjs.js",
module: "dist/pkg.esm.js",
}),
"src/index.js": js`
console.log(import.meta.url);
`,
});
await dev(tmpPath);
// i would require it but i don't want jest to do magical things
let { code, stdout, stderr } = await spawn("node", [tmpPath], {
env: {
PATH: process.env.PATH,
},
});
expect(stderr.toString()).toBe("");
expect(code).toBe(0);
expect(stdout.toString()).toBe(
pathToFileURL(path.join(tmpPath, "src/index.js")).toString() + "\n"
);
});
30 changes: 15 additions & 15 deletions packages/cli/src/build/__tests__/__snapshots__/basic.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = "something";

exports.default = index;
exports["default"] = index;
"
`;

Expand All @@ -29,14 +29,14 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = "something";

exports.default = index;
exports["default"] = index;
"
`;

exports[`basic: valid-package.esm.js 1`] = `
"var index = "something";

export default index;
export { index as default };
"
`;

Expand Down Expand Up @@ -73,13 +73,13 @@ exports[`typescript thing: weird-typescript-thing.cjs.dev.js 1`] = `

Object.defineProperty(exports, '__esModule', { value: true });

const thing = () => "wow";
const thing$1 = () => "wow";

const makeThing = () => thing();
const makeThing = () => thing$1();

const thing$1 = makeThing();
const thing = makeThing();

exports.thing = thing$1;
exports.thing = thing;
"
`;

Expand All @@ -99,23 +99,23 @@ exports[`typescript thing: weird-typescript-thing.cjs.prod.js 1`] = `

Object.defineProperty(exports, '__esModule', { value: true });

const thing = () => "wow";
const thing$1 = () => "wow";

const makeThing = () => thing();
const makeThing = () => thing$1();

const thing$1 = makeThing();
const thing = makeThing();

exports.thing = thing$1;
exports.thing = thing;
"
`;

exports[`typescript thing: weird-typescript-thing.esm.js 1`] = `
"const thing = () => "wow";
"const thing$1 = () => "wow";

const makeThing = () => thing();
const makeThing = () => thing$1();

const thing$1 = makeThing();
const thing = makeThing();

export { thing$1 as thing };
export { thing };
"
`;
37 changes: 18 additions & 19 deletions packages/cli/src/build/__tests__/__snapshots__/build.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function doSomething(arg) {
}
var index = "wow";

exports.default = index;
exports["default"] = index;
exports.doSomething = doSomething;
"
`;
Expand Down Expand Up @@ -103,7 +103,7 @@ function doSomething(arg) {
}
var index = "wow";

exports.default = index;
exports["default"] = index;
exports.doSomething = doSomething;
"
`;
Expand All @@ -114,8 +114,7 @@ exports[`flow: flow-export-default.esm.js 1`] = `
}
var index = "wow";

export default index;
export { doSomething };
export { index as default, doSomething };
"
`;

Expand All @@ -126,7 +125,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = 2;

exports.default = index;
exports["default"] = index;
"
`;

Expand All @@ -148,14 +147,14 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = 2;

exports.default = index;
exports["default"] = index;
"
`;

exports[`monorepo single package: some-scope-package-two-single-package.esm.js 1`] = `
"var index = 2;

export default index;
export { index as default };
"
`;

Expand Down Expand Up @@ -192,7 +191,7 @@ exports[`monorepo umd with dep on other module: some-scope-package-four-umd-with
"
`;

exports[`monorepo umd with dep on other module: some-scope-package-four-umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"some-scope-package-four-umd-with-dep.umd.min.js","sources":["../../package-one/src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"div\\", null);"],"names":[],"mappings":"iQAEc,MAAO"}"`;
exports[`monorepo umd with dep on other module: some-scope-package-four-umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"some-scope-package-four-umd-with-dep.umd.min.js","sources":["../../package-one/src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"div\\", null);"],"names":["createElement"],"mappings":"iPAEAA,EAAAA,cAAc,MAAO"}"`;

exports[`monorepo umd with dep on other module: some-scope-package-one-umd-with-dep.cjs.dev.js 1`] = `
"'use strict';
Expand Down Expand Up @@ -229,7 +228,7 @@ exports[`monorepo umd with dep on other module: some-scope-package-one-umd-with-
"
`;

exports[`monorepo umd with dep on other module: some-scope-package-one-umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"some-scope-package-one-umd-with-dep.umd.min.js","sources":["../src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"div\\", null);"],"names":[],"mappings":"iQAEc,MAAO"}"`;
exports[`monorepo umd with dep on other module: some-scope-package-one-umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"some-scope-package-one-umd-with-dep.umd.min.js","sources":["../src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"div\\", null);"],"names":["createElement"],"mappings":"iPAEAA,EAAAA,cAAc,MAAO"}"`;

exports[`monorepo umd with dep on other module: some-scope-package-three-umd-with-dep.cjs.dev.js 1`] = `
"'use strict';
Expand Down Expand Up @@ -301,7 +300,7 @@ exports[`monorepo umd with dep on other module: some-scope-package-two-umd-with-
"
`;

exports[`monorepo umd with dep on other module: some-scope-package-two-umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"some-scope-package-two-umd-with-dep.umd.min.js","sources":["../src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"h1\\", null);"],"names":[],"mappings":"iQAEc,KAAM"}"`;
exports[`monorepo umd with dep on other module: some-scope-package-two-umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"some-scope-package-two-umd-with-dep.umd.min.js","sources":["../src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"h1\\", null);"],"names":["createElement"],"mappings":"iPAEAA,EAAAA,cAAc,KAAM"}"`;

exports[`monorepo: some-scope-package-one.cjs.dev.js 1`] = `
"'use strict';
Expand All @@ -310,7 +309,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = 1;

exports.default = index;
exports["default"] = index;
"
`;

Expand All @@ -332,14 +331,14 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = 1;

exports.default = index;
exports["default"] = index;
"
`;

exports[`monorepo: some-scope-package-one.esm.js 1`] = `
"var index = 1;

export default index;
export { index as default };
"
`;

Expand All @@ -350,7 +349,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = 2;

exports.default = index;
exports["default"] = index;
"
`;

Expand All @@ -372,14 +371,14 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = 2;

exports.default = index;
exports["default"] = index;
"
`;

exports[`monorepo: some-scope-package-two.esm.js 1`] = `
"var index = 2;

export default index;
export { index as default };
"
`;

Expand All @@ -390,7 +389,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = "this does not have a module build";

exports.default = index;
exports["default"] = index;
"
`;

Expand All @@ -412,7 +411,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = "this does not have a module build";

exports.default = index;
exports["default"] = index;
"
`;

Expand Down Expand Up @@ -491,4 +490,4 @@ exports[`umd with dep on other module: umd-with-dep.umd.min.js 1`] = `
"
`;

exports[`umd with dep on other module: umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"umd-with-dep.umd.min.js","sources":["../src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"div\\", null);"],"names":[],"mappings":"iQAEc,MAAO"}"`;
exports[`umd with dep on other module: umd-with-dep.umd.min.js.map 1`] = `"{"version":3,"file":"umd-with-dep.umd.min.js","sources":["../src/index.js"],"sourcesContent":["import { createElement } from \\"react\\";\\n\\ncreateElement(\\"div\\", null);"],"names":["createElement"],"mappings":"iPAEAA,EAAAA,cAAc,MAAO"}"`;
16 changes: 8 additions & 8 deletions packages/cli/src/build/__tests__/__snapshots__/other.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let thing = "wow";
}
var thing$1 = thing;

exports.default = thing$1;
exports["default"] = thing$1;
"
`;

Expand All @@ -32,7 +32,7 @@ if (typeof document !== undefined) {
}
var thing$1 = thing;

exports.default = thing$1;
exports["default"] = thing$1;
"
`;

Expand Down Expand Up @@ -61,7 +61,7 @@ if (typeof document !== undefined) {
}
var thing$1 = thing;

exports.default = thing$1;
exports["default"] = thing$1;
"
`;

Expand Down Expand Up @@ -96,7 +96,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = "something";

exports.default = index;
exports["default"] = index;
"
`;

Expand All @@ -118,7 +118,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

var index = "something";

exports.default = index;
exports["default"] = index;
"
`;

Expand Down Expand Up @@ -245,7 +245,7 @@ var Foo = /*#__PURE__*/_createClass(function Foo() {
_classCallCheck(this, Foo);
});

exports.default = Foo;
exports["default"] = Foo;
"
`;

Expand All @@ -272,7 +272,7 @@ var Foo = /*#__PURE__*/_createClass(function Foo() {
_classCallCheck(this, Foo);
});

exports.default = Foo;
exports["default"] = Foo;
"
`;

Expand All @@ -284,7 +284,7 @@ var Foo = /*#__PURE__*/_createClass(function Foo() {
_classCallCheck(this, Foo);
});

export default Foo;
export { Foo as default };
"
`;

Expand Down