Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Jan 15, 2024
1 parent c563fbb commit 3cd7ae3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 38 deletions.
7 changes: 0 additions & 7 deletions packages/cli/src/build/__tests__/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2324,13 +2324,6 @@ test("type: module", async () => {
export { a };
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ multiply/dist/multiple-entrypoints-multiply.d.ts ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
export * from "../../src/multiply";
//# sourceMappingURL=multiple-entrypoints-multiply.d.ts.map
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ multiply/dist/multiple-entrypoints-multiply.d.ts.map ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
{"version":3,"file":"multiple-entrypoints-multiply.d.ts","sourceRoot":"","sources":["../../src/multiply.ts"],"names":[],"mappings":"AAAA"}
`);
let node = await spawn("node", ["runtime-blah.mjs"], { cwd: dir });

Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ export async function cleanProjectBeforeBuild(project: Project) {
return fs.remove(path.join(entrypoint.directory, "dist"));
}),
]);
const isTypeModule = pkg.isTypeModule();

await Promise.all(
pkg.entrypoints.map(async (entrypoint) => {
if (isTsPath(entrypoint.source)) {
await fs.mkdir(path.join(entrypoint.directory, "dist"));
if (!isTypeModule) {
await fs.mkdir(path.join(entrypoint.directory, "dist"));
}
await writeDevTSFiles(
entrypoint,
await entrypointHasDefaultExport(
Expand Down
84 changes: 54 additions & 30 deletions packages/cli/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ export async function writeDevTSFiles(
entrypoint: Entrypoint,
hasDefaultExport: boolean
) {
const dtsReexportFilename = entrypoint.package.isTypeModule()
? path.join(
entrypoint.package.directory,
"dist",
getBaseDistName(entrypoint) + ".d.ts"
)
: path
.join(entrypoint.directory, validFieldsForEntrypoint.main(entrypoint))
.replace(/\.js$/, ".d.ts");
const dtsReexportFilename = path.join(
(entrypoint.package.project.experimentalFlags.distInRoot
? entrypoint.package
: entrypoint
).directory,
"dist",
getBaseDistName(entrypoint) +
(entrypoint.package.isTypeModule() ? "" : ".cjs") +
".d.ts"
);

const baseDtsFilename = path.basename(dtsReexportFilename);
const relativePathWithExtension = normalizePath(
Expand Down Expand Up @@ -123,11 +124,8 @@ export async function writeDevTSFiles(
!entrypoint.package.isTypeModule()
) {
const dmtsReexportFilename = path
.join(
entrypoint.package.directory,
getExportsImportUnwrappingDefaultOutputPath(entrypoint)
)
.replace(/\.mjs$/, ".d.mts");
.join(entrypoint.directory, validFieldsForEntrypoint.main(entrypoint))
.replace(/\.js$/, ".d.mts");
const baseDmtsFilename = path.basename(dmtsReexportFilename);

const ext = path.extname(relativePathWithExtension).slice(1);
Expand Down Expand Up @@ -191,8 +189,11 @@ export default async function dev(projectDir: string) {
info("project is valid!");

await Promise.all(
project.packages.map((pkg) => {
project.packages.map(async (pkg) => {
const exportsFieldConfig = pkg.exportsFieldConfig();
let distDirectory = path.join(pkg.directory, "dist");
await fs.remove(distDirectory);
await fs.ensureDir(distDirectory);

return Promise.all(
pkg.entrypoints.map(async (entrypoint) => {
Expand Down Expand Up @@ -253,16 +254,27 @@ export default async function dev(projectDir: string) {
? pkg.directory
: entrypoint.directory;
entrypointPromises.push(
fs.symlink(
entrypoint.source,
path.join(
distRoot,
getDistFilenameForConditions(
entrypoint,
conditions.concat("module")
fs
.symlink(
entrypoint.source,
path.join(
distRoot,
getDistFilenameForConditions(
entrypoint,
conditions.concat("module")
)
)
)
),
.catch((err) => {
console.log(

Check warning on line 269 in packages/cli/src/dev.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/dev.ts#L268-L269

Added lines #L268 - L269 were not covered by tests
distRoot,
err,
getDistFilenameForConditions(
entrypoint,
conditions.concat("module")
)
);
}),
fs.writeFile(
path.join(
distRoot,
Expand Down Expand Up @@ -361,13 +373,22 @@ export default async function dev(projectDir: string) {
}
if (entrypoint.json.module) {
entrypointPromises.push(
fs.symlink(
entrypoint.source,
path.join(
entrypoint.directory,
validFieldsForEntrypoint.module(entrypoint)
fs
.symlink(
entrypoint.source,
path.join(
entrypoint.directory,
validFieldsForEntrypoint.module(entrypoint)
)
)
)
.catch((err) => {
console.log(

Check warning on line 385 in packages/cli/src/dev.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/dev.ts#L384-L385

Added lines #L384 - L385 were not covered by tests
path.join(
entrypoint.directory,
validFieldsForEntrypoint.module(entrypoint)
)
);
})
);
}

Expand Down Expand Up @@ -405,10 +426,13 @@ export default async function dev(projectDir: string) {
}

async function cleanEntrypoint(entrypoint: Entrypoint) {
if (entrypoint.package.name === entrypoint.name) return;
let distDirectory = path.join(entrypoint.directory, "dist");

await fs.remove(distDirectory);
await fs.ensureDir(distDirectory);
if (!entrypoint.package.project.experimentalFlags.distInRoot) {
await fs.ensureDir(distDirectory);
}
}

function commonjsRequireHookTemplate(entrypoint: Entrypoint) {
Expand Down

0 comments on commit 3cd7ae3

Please sign in to comment.