Skip to content

Commit

Permalink
chore: rename top to entry
Browse files Browse the repository at this point in the history
  • Loading branch information
SegaraRai committed Jul 24, 2024
1 parent 543d73b commit 8271700
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 286 deletions.
8 changes: 4 additions & 4 deletions src/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ContentSpec, Layer, LayerMode } from "../options";
import type { createTailwindCSSGenerator } from "../tailwindcss";
import { assertsNever } from "../utils";
import type { CodegenContext } from "./context";
import { generateModuleJSCode, generateTopJSCode } from "./js";
import { generateEntryJSCode, generateModuleJSCode } from "./js";
import {
getFilteredModuleImportsRecursive,
waitAndResolveAllModuleIds,
Expand Down Expand Up @@ -54,13 +54,13 @@ export async function generateCode(
const { warn } = functions;

switch (mode) {
case "top": {
const topJSCode = await generateTopJSCode(
case "entry": {
const entryJSCode = await generateEntryJSCode(
parsedId,
codegenContext,
skipLayer
);
return [topJSCode, parsedId.inject];
return [entryJSCode, parsedId.inject];
}

case "module": {
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/js.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
stringifyId,
type TailwindModuleId,
type TailwindModuleIdEntry,
type TailwindModuleIdModuleJS,
type TailwindModuleIdTop,
} from "../id";
import type { Layer } from "../options";
import { assertsNever } from "../utils";
Expand Down Expand Up @@ -62,8 +62,8 @@ function createImportCodegen(inject: boolean, functions: CodegenFunctions) {
};
}

export async function generateTopJSCode(
{ source, inject, shallow }: TailwindModuleIdTop,
export async function generateEntryJSCode(
{ source, inject, shallow }: TailwindModuleIdEntry,
{ functions, options: { allowCircularModules, layers } }: CodegenContext,
skipLayer: (layer: Layer, layerIndex: number) => boolean
): Promise<string> {
Expand Down
32 changes: 16 additions & 16 deletions src/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export type CodegenFunctionsForId = Pick<
"parseId" | "stringifyId"
>;

export interface TailwindModuleIdTop {
readonly mode: "top";
export interface TailwindModuleIdEntry {
readonly mode: "entry";
readonly extension: "js";
readonly shallow: boolean;
readonly inject: boolean;
Expand Down Expand Up @@ -49,13 +49,13 @@ export interface TailwindModuleIdModuleCSS {
}

export type TailwindModuleId =
| TailwindModuleIdTop
| TailwindModuleIdEntry
| TailwindModuleIdGlobal
| TailwindModuleIdHoisted
| TailwindModuleIdModuleJS
| TailwindModuleIdModuleCSS;

const TOP_IMPORT_SPEC_RE = /[#?]tailwindcss(?:\/([^/]*))?$/;
const ENTRY_IMPORT_SPEC_RE = /[#?]tailwindcss(?:\/([^/]*))?$/;

export function resolveId(
source: string,
Expand All @@ -66,7 +66,7 @@ export function resolveId(
return source;
}

const match = TOP_IMPORT_SPEC_RE.exec(source);
const match = ENTRY_IMPORT_SPEC_RE.exec(source);
if (!match) {
return;
}
Expand All @@ -93,7 +93,7 @@ export function resolveId(

return stringifyId(
{
mode: "top",
mode: "entry",
extension: "js",
shallow,
inject,
Expand All @@ -109,7 +109,7 @@ export async function resolveIdFromURL(
resolveIdFromPath: (path: string) => string | Promise<string>,
funcs: CodegenFunctionsForId
): Promise<string | undefined> {
const match = TOP_IMPORT_SPEC_RE.exec(url);
const match = ENTRY_IMPORT_SPEC_RE.exec(url);
if (!match) {
return;
}
Expand All @@ -122,7 +122,7 @@ export async function resolveIdFromURL(

return stringifyId(
{
mode: "top",
mode: "entry",
extension: "js",
shallow,
inject,
Expand Down Expand Up @@ -164,13 +164,13 @@ export function parseId(
};
}

const [, topSpecifier] = /^top\.([a-z]+)\.js/.exec(name) ?? [];
if (topSpecifier) {
const shallow = topSpecifier.includes("s");
const inject = topSpecifier.includes("j");
const [, entrySpecifier] = /^entry\.([a-z]+)\.js/.exec(name) ?? [];
if (entrySpecifier) {
const shallow = entrySpecifier.includes("s");
const inject = entrySpecifier.includes("j");

return {
mode: "top",
mode: "entry",
extension: "js",
shallow,
inject,
Expand Down Expand Up @@ -252,11 +252,11 @@ export function stringifyId(
}

switch (id.mode) {
case "top":
case "entry":
if (inject !== id.inject) {
throw new Error("LogicError: inject specifier mismatch for top code");
throw new Error("LogicError: inject specifier mismatch for entry code");
}
return stringifyId(id.source, `top.${spec}.js`);
return stringifyId(id.source, `entry.${spec}.js`);

case "hoisted":
return stringifyId(
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function modularTailwindCSSPluginBuild(options: Options): Plugin {
if (
!seenCircularDependencyWarning &&
shouldWarnIfCircular &&
parsedId.mode === "top"
parsedId.mode === "entry"
) {
if (await hasCircularDependencies(functions, parsedId.source)) {
seenCircularDependencyWarning = true;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/serveLite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function modularTailwindCSSPluginServeLite(options: Options): Plugin {
return;
}

if (parsedId.mode !== "top") {
if (parsedId.mode !== "entry") {
throw new Error(
`LogicError: ${parsedId.mode} code is not available in dev mode.`
);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/serveStrict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export function modularTailwindCSSPluginServeStrict(options: Options): Plugin {
if (
!seenCircularDependencyWarning &&
shouldWarnIfCircular &&
parsedId.mode === "top"
parsedId.mode === "entry"
) {
if (await hasCircularDependencies(functions, parsedId.source)) {
seenCircularDependencyWarning = true;
Expand Down
40 changes: 20 additions & 20 deletions tests/cases/circular.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ it("should handle circular dependencies with hoisted mode", async ({
export default m0 + s;
",
"[intermediate] tailwindcss/__x00__test/c.js/module.layer2.l.css?inline": "export default """,
"[intermediate] tailwindcss/__x00__test/entry.js/entry.dl.js": "import l0g from "\\u0000tailwindcss/global.layer0.l.css?inline";
import l1h from "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline";
import l2m from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dl.js";
export default l0g + l1h + l2m;
",
"[intermediate] tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline": "export default ".test-c-1 {\\n --test-c: 1px\\n}\\n.test-c-2 {\\n --test-c: 2px\\n}\\n.test-c-3 {\\n --test-c: 3px\\n}\\n.test-c-9 {\\n --test-c: 9px\\n}\\n"",
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.dl.js": "import m0 from "\\u0000tailwindcss/__x00__test/a.js/module.layer2.dl.js";
import s from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.l.css?inline";
export default m0 + s;
",
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.l.css?inline": "export default """,
"[intermediate] tailwindcss/__x00__test/entry.js/top.dl.js": "import l0g from "\\u0000tailwindcss/global.layer0.l.css?inline";
import l1h from "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline";
import l2m from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dl.js";
export default l0g + l1h + l2m;
",
"[intermediate] tailwindcss/global.layer0.l.css?inline": "export default "/* TailwindCSS Base */\\n/* TailwindCSS Base Backdrop */\\n"",
"[output] _virtual/a.js": "import { b1 } from "./b.js";
const a1 = () => "test-c-1 " + b1();
Expand All @@ -136,7 +136,15 @@ it("should handle circular dependencies with hoisted mode", async ({
c1
};
",
"[output] _virtual/entry.js": "import css from "./top.dl.js";
"[output] _virtual/entry.dl.js": "import l0g from "./global.layer0.l.css.js";
import l1h from "./hoisted.layer1.dl.css.js";
import l2m from "./module.layer2.dl.js";
const css = l0g + l1h + l2m;
export {
css as default
};
",
"[output] _virtual/entry.js": "import css from "./entry.dl.js";
import { a1 } from "./a.js";
console.log(a1(), css);
",
Expand Down Expand Up @@ -197,14 +205,6 @@ it("should handle circular dependencies with hoisted mode", async ({
export {
s as default
};
",
"[output] _virtual/top.dl.js": "import l0g from "./global.layer0.l.css.js";
import l1h from "./hoisted.layer1.dl.css.js";
import l2m from "./module.layer2.dl.js";
const css = l0g + l1h + l2m;
export {
css as default
};
",
"[output] tests/entry.html": "<!doctype html>
<html lang="en">
Expand All @@ -220,7 +220,7 @@ it("should handle circular dependencies with hoisted mode", async ({
<script type="module" crossorigin src="/_virtual/module.layer2.dl2.js"></script>
<script type="module" crossorigin src="/_virtual/module.layer2.l.css.js"></script>
<script type="module" crossorigin src="/_virtual/module.layer2.dl.js"></script>
<script type="module" crossorigin src="/_virtual/top.dl.js"></script>
<script type="module" crossorigin src="/_virtual/entry.dl.js"></script>
<script type="module" crossorigin src="/_virtual/c.js"></script>
<script type="module" crossorigin src="/_virtual/b.js"></script>
<script type="module" crossorigin src="/_virtual/a.js"></script>
Expand Down Expand Up @@ -291,18 +291,18 @@ it("should handle circular dependencies with module mode", async ({
export default f;
",
"[intermediate] tailwindcss/__x00__test/c.js/module.layer2.l.css?inline": "export default ".test-u-3 {\\n --test-u: 3px\\n}\\n"",
"[intermediate] tailwindcss/__x00__test/entry.js/entry.dl.js": "import l0g from "\\u0000tailwindcss/global.layer0.l.css?inline";
import l1h from "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline";
import l2m from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dl.js";
export default l0g + l1h + l2m();
",
"[intermediate] tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline": "export default """,
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.dl.js": "import m0 from "\\u0000tailwindcss/__x00__test/a.js/module.layer2.dl.js";
import s from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.l.css?inline";
const f = (...p) => p.includes(f) ? "" : m0(...p, f) + s;
export default f;
",
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.l.css?inline": "export default """,
"[intermediate] tailwindcss/__x00__test/entry.js/top.dl.js": "import l0g from "\\u0000tailwindcss/global.layer0.l.css?inline";
import l1h from "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline";
import l2m from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dl.js";
export default l0g + l1h + l2m();
",
"[intermediate] tailwindcss/global.layer0.l.css?inline": "export default "/* TailwindCSS Base */\\n/* TailwindCSS Base Backdrop */\\n"",
"[output] entry.js": "const l0g = "/* TailwindCSS Base */\\n/* TailwindCSS Base Backdrop */\\n";
const l1h = "";
Expand Down
38 changes: 19 additions & 19 deletions tests/cases/deep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ export default "test-u-2 test-c-2 test-b-2";
export default s;
",
"[intermediate] tailwindcss/__x00__test/b.js/module.layer2.l.css?inline": "export default ".test-u-3 {\\n --test-u: 3px\\n}\\n"",
"[intermediate] tailwindcss/__x00__test/entry.js/entry.dl.js": "import l0g from "\\u0000tailwindcss/global.layer0.l.css?inline";
import l1h from "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline";
import l2m from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dl.js";
export default l0g + l1h + l2m;
",
"[intermediate] tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline": "export default ".test-c-1 {\\n --test-c: 1px\\n}\\n.test-c-2 {\\n --test-c: 2px\\n}\\n.test-c-3 {\\n --test-c: 3px\\n}\\n"",
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.dl.js": "import m0 from "\\u0000tailwindcss/__x00__test/a.js/module.layer2.dl.js";
import s from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.l.css?inline";
export default m0 + s;
",
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.l.css?inline": "export default ".test-u-1 {\\n --test-u: 1px\\n}\\n"",
"[intermediate] tailwindcss/__x00__test/entry.js/top.dl.js": "import l0g from "\\u0000tailwindcss/global.layer0.l.css?inline";
import l1h from "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dl.css?inline";
import l2m from "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dl.js";
export default l0g + l1h + l2m;
",
"[intermediate] tailwindcss/global.layer0.l.css?inline": "export default ".test-b-1 {\\n --test-b: 1px\\n}\\n.test-b-2 {\\n --test-b: 2px\\n}\\n.test-b-3 {\\n --test-b: 3px\\n}\\n/* TailwindCSS Base */\\n/* TailwindCSS Base Backdrop */\\n"",
"[output] _virtual/a.js": "import "./b.js";
const a = "test-u-2 test-c-2 test-b-2";
Expand All @@ -68,7 +68,15 @@ export default "test-u-2 test-c-2 test-b-2";
",
"[output] _virtual/b.js": "console.log("test-u-3 test-c-3 test-b-3");
",
"[output] _virtual/entry.js": "import css from "./top.dl.js";
"[output] _virtual/entry.dl.js": "import l0g from "./global.layer0.l.css.js";
import l1h from "./hoisted.layer1.dl.css.js";
import l2m from "./module.layer2.dl.js";
const css = l0g + l1h + l2m;
export {
css as default
};
",
"[output] _virtual/entry.js": "import css from "./entry.dl.js";
import a from "./a.js";
const X = "test-u-1 test-c-1 test-b-1";
console.log(X, a, css);
Expand Down Expand Up @@ -116,14 +124,6 @@ export default "test-u-2 test-c-2 test-b-2";
export {
s as default
};
",
"[output] _virtual/top.dl.js": "import l0g from "./global.layer0.l.css.js";
import l1h from "./hoisted.layer1.dl.css.js";
import l2m from "./module.layer2.dl.js";
const css = l0g + l1h + l2m;
export {
css as default
};
",
"[output] tests/entry.html": "<!doctype html>
<html lang="en">
Expand All @@ -136,7 +136,7 @@ export default "test-u-2 test-c-2 test-b-2";
<script type="module" crossorigin src="/_virtual/module.layer2.dl2.js"></script>
<script type="module" crossorigin src="/_virtual/module.layer2.l.css.js"></script>
<script type="module" crossorigin src="/_virtual/module.layer2.dl.js"></script>
<script type="module" crossorigin src="/_virtual/top.dl.js"></script>
<script type="module" crossorigin src="/_virtual/entry.dl.js"></script>
<script type="module" crossorigin src="/_virtual/b.js"></script>
<script type="module" crossorigin src="/_virtual/a.js"></script>
<script type="module" crossorigin src="/_virtual/entry.js"></script>
Expand Down Expand Up @@ -194,15 +194,15 @@ export default "test-u-2 test-c-2 test-b-2";
"[intermediate] tailwindcss/__x00__test/b.js/module.layer2.dj.js": "import "\\u0000tailwindcss/__x00__test/b.js/module.layer2.j.css";
",
"[intermediate] tailwindcss/__x00__test/b.js/module.layer2.j.css": "",
"[intermediate] tailwindcss/__x00__test/entry.js/entry.dj.js": "import "\\u0000tailwindcss/global.layer0.j.css";
import "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dj.css";
import "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dj.js";
",
"[intermediate] tailwindcss/__x00__test/entry.js/hoisted.layer1.dj.css": "",
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.dj.js": "import "\\u0000tailwindcss/__x00__test/a.js/module.layer2.dj.js";
import "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.j.css";
",
"[intermediate] tailwindcss/__x00__test/entry.js/module.layer2.j.css": "",
"[intermediate] tailwindcss/__x00__test/entry.js/top.dj.js": "import "\\u0000tailwindcss/global.layer0.j.css";
import "\\u0000tailwindcss/__x00__test/entry.js/hoisted.layer1.dj.css";
import "\\u0000tailwindcss/__x00__test/entry.js/module.layer2.dj.js";
",
"[intermediate] tailwindcss/global.layer0.j.css": "",
"[output] _virtual/a.js": "import "./b.js";
const a = "test-u-2 test-c-2 test-b-2";
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/global-fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ it("supports filesystem content", async ({ expect }) => {

expect(files).toMatchInlineSnapshot(`
{
"[intermediate] tailwindcss/__x00__test/entry.js/top.dj.js": "import "\\u0000tailwindcss/global.layer0.j.css";
"[intermediate] tailwindcss/__x00__test/entry.js/entry.dj.js": "import "\\u0000tailwindcss/global.layer0.j.css";
",
"[intermediate] tailwindcss/global.layer0.j.css": "",
"[output] _virtual/entry.js": "/* empty css */
Expand Down
Loading

0 comments on commit 8271700

Please sign in to comment.