@pandacss/node 0.0.0-dev-20230513102701 → 0.0.0-dev-20230515185702
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +16 -9
- package/dist/index.js +191 -98
- package/dist/index.mjs +181 -88
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -176,20 +176,27 @@ declare function analyzeTokens(ctx: PandaContext, options?: {
|
|
|
176
176
|
};
|
|
177
177
|
declare const writeAnalyzeJSON: (fileName: string, result: ReturnType<typeof analyzeTokens>, ctx: PandaContext) => Promise<void>;
|
|
178
178
|
|
|
179
|
+
type ConfigDepsResult = {
|
|
180
|
+
modifiedMap: Map<string, number>;
|
|
181
|
+
isModified: boolean;
|
|
182
|
+
};
|
|
179
183
|
declare class Builder {
|
|
180
184
|
/**
|
|
181
|
-
*
|
|
182
|
-
*/
|
|
183
|
-
fileModifiedMap: Map<string, number>;
|
|
184
|
-
/**
|
|
185
|
-
* Map of file path to css
|
|
185
|
+
* The current panda context
|
|
186
186
|
*/
|
|
187
|
-
fileCssMap: Map<string, string>;
|
|
188
187
|
context: PandaContext | undefined;
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
writeFileCss(file: string, css: string): void;
|
|
189
|
+
checkConfigDeps(configPath: string, deps: Set<string>): ConfigDepsResult;
|
|
190
|
+
getConfigPath(): string;
|
|
191
191
|
setup(): Promise<void>;
|
|
192
|
-
|
|
192
|
+
setupContext(options: {
|
|
193
|
+
configPath: string;
|
|
194
|
+
depsModifiedMap: Map<string, number>;
|
|
195
|
+
}): Promise<void>;
|
|
196
|
+
getContextOrThrow(): PandaContext;
|
|
197
|
+
get fileModifiedMap(): Map<string, number>;
|
|
198
|
+
get fileCssMap(): Map<string, string>;
|
|
199
|
+
extractFile(ctx: PandaContext, file: string): Promise<string | undefined>;
|
|
193
200
|
extract(): Promise<void>;
|
|
194
201
|
toString(): string;
|
|
195
202
|
isValidRoot(root: Root): boolean;
|
package/dist/index.js
CHANGED
|
@@ -885,10 +885,9 @@ init_cjs_shims();
|
|
|
885
885
|
var import_core2 = require("@pandacss/core");
|
|
886
886
|
var import_error = require("@pandacss/error");
|
|
887
887
|
var import_logger4 = require("@pandacss/logger");
|
|
888
|
-
var
|
|
889
|
-
var import_fs = require("fs");
|
|
888
|
+
var import_fs2 = require("fs");
|
|
890
889
|
var import_fs_extra2 = require("fs-extra");
|
|
891
|
-
var
|
|
890
|
+
var import_path4 = require("path");
|
|
892
891
|
|
|
893
892
|
// src/config.ts
|
|
894
893
|
init_cjs_shims();
|
|
@@ -904,18 +903,18 @@ var import_lil_fp = require("lil-fp");
|
|
|
904
903
|
// src/chunk-engine.ts
|
|
905
904
|
init_cjs_shims();
|
|
906
905
|
var import_core = require("@pandacss/core");
|
|
907
|
-
var getChunkEngine = ({ paths, config, runtime: { path:
|
|
908
|
-
dir:
|
|
906
|
+
var getChunkEngine = ({ paths, config, runtime: { path: path3, fs: fs3 } }) => ({
|
|
907
|
+
dir: path3.join(...paths.chunk),
|
|
909
908
|
readFile(file) {
|
|
910
|
-
const fileName =
|
|
911
|
-
return
|
|
909
|
+
const fileName = path3.join(...paths.chunk, this.format(file));
|
|
910
|
+
return fs3.existsSync(fileName) ? fs3.readFileSync(fileName) : "";
|
|
912
911
|
},
|
|
913
912
|
getFiles() {
|
|
914
|
-
const files =
|
|
915
|
-
return files.map((file) =>
|
|
913
|
+
const files = fs3.existsSync(this.dir) ? fs3.readDirSync(this.dir) : [];
|
|
914
|
+
return files.map((file) => fs3.readFileSync(path3.join(this.dir, file)));
|
|
916
915
|
},
|
|
917
916
|
format(file) {
|
|
918
|
-
return
|
|
917
|
+
return path3.relative(config.cwd, file).replaceAll(path3.sep, "__").replace(path3.extname(file), ".css");
|
|
919
918
|
},
|
|
920
919
|
getArtifact(file, css) {
|
|
921
920
|
const fileName = this.format(file);
|
|
@@ -926,10 +925,10 @@ var getChunkEngine = ({ paths, config, runtime: { path: path2, fs: fs2 } }) => (
|
|
|
926
925
|
};
|
|
927
926
|
},
|
|
928
927
|
rm(file) {
|
|
929
|
-
return
|
|
928
|
+
return fs3.rmFileSync(path3.join(...paths.chunk, this.format(file)));
|
|
930
929
|
},
|
|
931
930
|
empty() {
|
|
932
|
-
return
|
|
931
|
+
return fs3.rmDirSync(this.dir);
|
|
933
932
|
},
|
|
934
933
|
get glob() {
|
|
935
934
|
return [`${this.dir}/**/*.css`];
|
|
@@ -976,8 +975,8 @@ var nodeRuntime = {
|
|
|
976
975
|
readDirSync: import_fs_extra.readdirSync,
|
|
977
976
|
rmDirSync: import_fs_extra.emptyDirSync,
|
|
978
977
|
rmFileSync: import_fs_extra.removeSync,
|
|
979
|
-
ensureDirSync(
|
|
980
|
-
return (0, import_fs_extra.ensureDirSync)(
|
|
978
|
+
ensureDirSync(path3) {
|
|
979
|
+
return (0, import_fs_extra.ensureDirSync)(path3);
|
|
981
980
|
},
|
|
982
981
|
watch(options) {
|
|
983
982
|
const { include, exclude, cwd, poll } = options;
|
|
@@ -1008,20 +1007,20 @@ process.on("uncaughtException", (reason) => {
|
|
|
1008
1007
|
|
|
1009
1008
|
// src/output-engine.ts
|
|
1010
1009
|
init_cjs_shims();
|
|
1011
|
-
var getOutputEngine = ({ paths, runtime: { path:
|
|
1010
|
+
var getOutputEngine = ({ paths, runtime: { path: path3, fs: fs3 } }) => ({
|
|
1012
1011
|
empty() {
|
|
1013
|
-
|
|
1012
|
+
fs3.rmDirSync(path3.join(...paths.root));
|
|
1014
1013
|
},
|
|
1015
1014
|
async write(output) {
|
|
1016
1015
|
if (!output)
|
|
1017
1016
|
return;
|
|
1018
1017
|
const { dir = paths.root, files } = output;
|
|
1019
|
-
|
|
1018
|
+
fs3.ensureDirSync(path3.join(...dir));
|
|
1020
1019
|
return Promise.all(
|
|
1021
1020
|
files.map(async ({ file, code }) => {
|
|
1022
|
-
const absPath =
|
|
1021
|
+
const absPath = path3.join(...dir, file);
|
|
1023
1022
|
if (code) {
|
|
1024
|
-
return
|
|
1023
|
+
return fs3.writeFile(absPath, code);
|
|
1025
1024
|
}
|
|
1026
1025
|
})
|
|
1027
1026
|
);
|
|
@@ -1036,14 +1035,14 @@ var createContext = (conf) => (0, import_lil_fp.pipe)(
|
|
|
1036
1035
|
(0, import_lil_fp.tap)(({ config, runtime }) => {
|
|
1037
1036
|
config.cwd ||= runtime.cwd();
|
|
1038
1037
|
}),
|
|
1039
|
-
import_lil_fp.Obj.bind("getFiles", ({ config, runtime: { fs:
|
|
1038
|
+
import_lil_fp.Obj.bind("getFiles", ({ config, runtime: { fs: fs3 } }) => () => {
|
|
1040
1039
|
const { include, exclude, cwd } = config;
|
|
1041
|
-
return
|
|
1040
|
+
return fs3.glob({ include, exclude, cwd });
|
|
1042
1041
|
}),
|
|
1043
|
-
import_lil_fp.Obj.bind("project", ({ getFiles, runtime: { fs:
|
|
1042
|
+
import_lil_fp.Obj.bind("project", ({ getFiles, runtime: { fs: fs3 }, parserOptions }) => {
|
|
1044
1043
|
return (0, import_parser.createProject)({
|
|
1045
1044
|
getFiles,
|
|
1046
|
-
readFile:
|
|
1045
|
+
readFile: fs3.readFileSync,
|
|
1047
1046
|
parserOptions
|
|
1048
1047
|
});
|
|
1049
1048
|
}),
|
|
@@ -2376,8 +2375,8 @@ async function bundleChunks(ctx) {
|
|
|
2376
2375
|
});
|
|
2377
2376
|
}
|
|
2378
2377
|
async function writeFileChunk(ctx, file) {
|
|
2379
|
-
const { path:
|
|
2380
|
-
import_logger3.logger.debug("chunk:write", `File: ${
|
|
2378
|
+
const { path: path3 } = ctx.runtime;
|
|
2379
|
+
import_logger3.logger.debug("chunk:write", `File: ${path3.relative(ctx.config.cwd, file)}`);
|
|
2381
2380
|
const css = extractFile(ctx, file);
|
|
2382
2381
|
if (!css)
|
|
2383
2382
|
return;
|
|
@@ -2386,11 +2385,11 @@ async function writeFileChunk(ctx, file) {
|
|
|
2386
2385
|
}
|
|
2387
2386
|
function extractFile(ctx, file) {
|
|
2388
2387
|
const {
|
|
2389
|
-
runtime: { path:
|
|
2388
|
+
runtime: { path: path3 },
|
|
2390
2389
|
config: { cwd }
|
|
2391
2390
|
} = ctx;
|
|
2392
2391
|
return (0, import_lil_fp2.pipe)(
|
|
2393
|
-
{ file:
|
|
2392
|
+
{ file: path3.abs(cwd, file) },
|
|
2394
2393
|
(0, import_lil_fp2.tap)(() => import_logger3.logger.debug("file:extract", file)),
|
|
2395
2394
|
import_lil_fp2.Obj.bind("measure", () => import_logger3.logger.time.debug(`Extracted ${file}`)),
|
|
2396
2395
|
import_lil_fp2.Obj.bind(
|
|
@@ -2432,10 +2431,62 @@ async function extractCss(ctx) {
|
|
|
2432
2431
|
return ctx.messages.buildComplete(ctx.getFiles().length);
|
|
2433
2432
|
}
|
|
2434
2433
|
|
|
2434
|
+
// src/get-mod-deps.ts
|
|
2435
|
+
init_cjs_shims();
|
|
2436
|
+
var import_fs = __toESM(require("fs"));
|
|
2437
|
+
var import_path2 = __toESM(require("path"));
|
|
2438
|
+
var jsExtensions = [".js", ".cjs", ".mjs"];
|
|
2439
|
+
var jsResolutionOrder = ["", ".js", ".cjs", ".mjs", ".ts", ".cts", ".mts", ".jsx", ".tsx"];
|
|
2440
|
+
var tsResolutionOrder = ["", ".ts", ".cts", ".mts", ".tsx", ".js", ".cjs", ".mjs", ".jsx"];
|
|
2441
|
+
function resolveWithExtension(file, extensions) {
|
|
2442
|
+
for (const ext of extensions) {
|
|
2443
|
+
const full = `${file}${ext}`;
|
|
2444
|
+
if (import_fs.default.existsSync(full) && import_fs.default.statSync(full).isFile()) {
|
|
2445
|
+
return full;
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
for (const ext of extensions) {
|
|
2449
|
+
const full = `${file}/index${ext}`;
|
|
2450
|
+
if (import_fs.default.existsSync(full)) {
|
|
2451
|
+
return full;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
return null;
|
|
2455
|
+
}
|
|
2456
|
+
function* getDeps(filename, base, seen, ext = import_path2.default.extname(filename)) {
|
|
2457
|
+
const absoluteFile = resolveWithExtension(
|
|
2458
|
+
import_path2.default.resolve(base, filename),
|
|
2459
|
+
jsExtensions.includes(ext) ? jsResolutionOrder : tsResolutionOrder
|
|
2460
|
+
);
|
|
2461
|
+
if (absoluteFile === null)
|
|
2462
|
+
return;
|
|
2463
|
+
if (seen.has(absoluteFile))
|
|
2464
|
+
return;
|
|
2465
|
+
seen.add(absoluteFile);
|
|
2466
|
+
yield absoluteFile;
|
|
2467
|
+
base = import_path2.default.dirname(absoluteFile);
|
|
2468
|
+
ext = import_path2.default.extname(absoluteFile);
|
|
2469
|
+
const contents = import_fs.default.readFileSync(absoluteFile, "utf-8");
|
|
2470
|
+
for (const match2 of [
|
|
2471
|
+
...contents.matchAll(/import[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
2472
|
+
...contents.matchAll(/import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
2473
|
+
...contents.matchAll(/require\(['"`](.+)['"`]\)/gi)
|
|
2474
|
+
]) {
|
|
2475
|
+
if (!match2[1].startsWith("."))
|
|
2476
|
+
continue;
|
|
2477
|
+
yield* getDeps(match2[1], base, seen, ext);
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
function getModuleDependencies(filePath) {
|
|
2481
|
+
if (filePath === null)
|
|
2482
|
+
return /* @__PURE__ */ new Set();
|
|
2483
|
+
return new Set(getDeps(filePath, import_path2.default.dirname(filePath), /* @__PURE__ */ new Set()));
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2435
2486
|
// src/parse-dependency.ts
|
|
2436
2487
|
init_cjs_shims();
|
|
2437
2488
|
var import_is_glob = __toESM(require("is-glob"));
|
|
2438
|
-
var
|
|
2489
|
+
var import_path3 = require("path");
|
|
2439
2490
|
|
|
2440
2491
|
// src/parse-glob.ts
|
|
2441
2492
|
init_cjs_shims();
|
|
@@ -2466,9 +2517,9 @@ function parseDependency(fileOrGlob) {
|
|
|
2466
2517
|
let message = null;
|
|
2467
2518
|
if ((0, import_is_glob.default)(fileOrGlob)) {
|
|
2468
2519
|
const { base, glob: glob2 } = parseGlob(fileOrGlob);
|
|
2469
|
-
message = { type: "dir-dependency", dir: (0,
|
|
2520
|
+
message = { type: "dir-dependency", dir: (0, import_path3.resolve)(base), glob: glob2 };
|
|
2470
2521
|
} else {
|
|
2471
|
-
message = { type: "dependency", file: (0,
|
|
2522
|
+
message = { type: "dependency", file: (0, import_path3.resolve)(fileOrGlob) };
|
|
2472
2523
|
}
|
|
2473
2524
|
if (message.type === "dir-dependency" && process.env.ROLLUP_WATCH === "true") {
|
|
2474
2525
|
message = { type: "dependency", file: message.dir };
|
|
@@ -2477,78 +2528,120 @@ function parseDependency(fileOrGlob) {
|
|
|
2477
2528
|
}
|
|
2478
2529
|
|
|
2479
2530
|
// src/builder.ts
|
|
2480
|
-
var
|
|
2481
|
-
var
|
|
2482
|
-
function getConfigHash() {
|
|
2483
|
-
const file = findConfig();
|
|
2484
|
-
if (!file) {
|
|
2485
|
-
throw new import_error.ConfigNotFoundError();
|
|
2486
|
-
}
|
|
2487
|
-
return (0, import_shared.toHash)((0, import_fs.readFileSync)(file, "utf-8"));
|
|
2488
|
-
}
|
|
2531
|
+
var configCache = /* @__PURE__ */ new Map();
|
|
2532
|
+
var contentFilesCache = /* @__PURE__ */ new WeakMap();
|
|
2489
2533
|
var setupCount = 0;
|
|
2490
2534
|
var Builder = class {
|
|
2491
2535
|
/**
|
|
2492
|
-
*
|
|
2493
|
-
*/
|
|
2494
|
-
fileModifiedMap = /* @__PURE__ */ new Map();
|
|
2495
|
-
/**
|
|
2496
|
-
* Map of file path to css
|
|
2536
|
+
* The current panda context
|
|
2497
2537
|
*/
|
|
2498
|
-
fileCssMap = /* @__PURE__ */ new Map();
|
|
2499
2538
|
context;
|
|
2500
|
-
|
|
2501
|
-
writeFile(file, css) {
|
|
2539
|
+
writeFileCss(file, css) {
|
|
2502
2540
|
const oldCss = this.fileCssMap?.get(file) ?? "";
|
|
2503
2541
|
const newCss = (0, import_core2.mergeCss)(oldCss, css);
|
|
2504
2542
|
this.fileCssMap?.set(file, newCss);
|
|
2505
2543
|
}
|
|
2544
|
+
checkConfigDeps(configPath, deps) {
|
|
2545
|
+
let modified = false;
|
|
2546
|
+
const newModified = /* @__PURE__ */ new Map();
|
|
2547
|
+
const prevModified = configCache.get(configPath)?.depsModifiedMap;
|
|
2548
|
+
for (const file of deps) {
|
|
2549
|
+
const time = (0, import_fs_extra2.statSync)(file).mtimeMs;
|
|
2550
|
+
newModified.set(file, time);
|
|
2551
|
+
if (!prevModified || !prevModified.has(file) || time > prevModified.get(file)) {
|
|
2552
|
+
modified = true;
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
if (!modified) {
|
|
2556
|
+
return { isModified: false, modifiedMap: prevModified };
|
|
2557
|
+
}
|
|
2558
|
+
for (const file of deps) {
|
|
2559
|
+
delete require.cache[file];
|
|
2560
|
+
}
|
|
2561
|
+
if (setupCount > 0) {
|
|
2562
|
+
import_logger4.logger.info("postcss", "\u2699\uFE0F Config changed, reloading");
|
|
2563
|
+
}
|
|
2564
|
+
return { isModified: true, modifiedMap: newModified };
|
|
2565
|
+
}
|
|
2566
|
+
getConfigPath() {
|
|
2567
|
+
const configPath = findConfig();
|
|
2568
|
+
if (!configPath) {
|
|
2569
|
+
throw new import_error.ConfigNotFoundError();
|
|
2570
|
+
}
|
|
2571
|
+
return configPath;
|
|
2572
|
+
}
|
|
2506
2573
|
async setup() {
|
|
2507
|
-
const
|
|
2508
|
-
const
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
this.
|
|
2512
|
-
|
|
2513
|
-
|
|
2574
|
+
const configPath = this.getConfigPath();
|
|
2575
|
+
const configDeps = getModuleDependencies(configPath);
|
|
2576
|
+
const deps = this.checkConfigDeps(configPath, configDeps);
|
|
2577
|
+
if (deps.isModified) {
|
|
2578
|
+
return this.setupContext({
|
|
2579
|
+
configPath,
|
|
2580
|
+
depsModifiedMap: deps.modifiedMap
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
const cache = configCache.get(configPath);
|
|
2584
|
+
if (cache) {
|
|
2585
|
+
this.context = cache.context;
|
|
2586
|
+
this.context.project.reloadSourceFiles();
|
|
2514
2587
|
} else {
|
|
2515
|
-
this.
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
}
|
|
2519
|
-
this.fileCssMap = /* @__PURE__ */ new Map();
|
|
2520
|
-
this.fileModifiedMap = /* @__PURE__ */ new Map();
|
|
2521
|
-
contextCache.set(configHash, this.context);
|
|
2522
|
-
builderCache.set(this.context, { fileCssMap: this.fileCssMap, fileModifiedMap: this.fileModifiedMap });
|
|
2588
|
+
await this.setupContext({
|
|
2589
|
+
configPath,
|
|
2590
|
+
depsModifiedMap: deps.modifiedMap
|
|
2591
|
+
});
|
|
2523
2592
|
}
|
|
2524
2593
|
setupCount++;
|
|
2525
2594
|
}
|
|
2526
|
-
|
|
2527
|
-
|
|
2595
|
+
async setupContext(options) {
|
|
2596
|
+
const { configPath, depsModifiedMap } = options;
|
|
2597
|
+
this.context = await loadConfigAndCreateContext({ configPath });
|
|
2598
|
+
if (setupCount > 0) {
|
|
2599
|
+
emitArtifacts(this.context);
|
|
2600
|
+
}
|
|
2601
|
+
configCache.set(configPath, {
|
|
2602
|
+
context: this.context,
|
|
2603
|
+
deps: new Set(this.context.configDependencies),
|
|
2604
|
+
depsModifiedMap
|
|
2605
|
+
});
|
|
2606
|
+
contentFilesCache.set(this.context, {
|
|
2607
|
+
fileCssMap: /* @__PURE__ */ new Map(),
|
|
2608
|
+
fileModifiedMap: /* @__PURE__ */ new Map()
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
getContextOrThrow() {
|
|
2612
|
+
if (!this.context) {
|
|
2528
2613
|
throw new Error("context not loaded");
|
|
2614
|
+
}
|
|
2529
2615
|
return this.context;
|
|
2530
2616
|
}
|
|
2617
|
+
get fileModifiedMap() {
|
|
2618
|
+
const ctx = this.getContextOrThrow();
|
|
2619
|
+
return contentFilesCache.get(ctx).fileModifiedMap;
|
|
2620
|
+
}
|
|
2621
|
+
get fileCssMap() {
|
|
2622
|
+
const ctx = this.getContextOrThrow();
|
|
2623
|
+
return contentFilesCache.get(ctx).fileCssMap;
|
|
2624
|
+
}
|
|
2625
|
+
async extractFile(ctx, file) {
|
|
2626
|
+
const mtime = (0, import_fs2.existsSync)(file) ? (0, import_fs_extra2.statSync)(file).mtimeMs : -Infinity;
|
|
2627
|
+
const isUnchanged = this.fileModifiedMap.has(file) && mtime === this.fileModifiedMap.get(file);
|
|
2628
|
+
if (isUnchanged)
|
|
2629
|
+
return;
|
|
2630
|
+
const css = extractFile(ctx, file);
|
|
2631
|
+
if (!css)
|
|
2632
|
+
return;
|
|
2633
|
+
this.fileModifiedMap.set(file, mtime);
|
|
2634
|
+
this.writeFileCss(file, css);
|
|
2635
|
+
return css;
|
|
2636
|
+
}
|
|
2531
2637
|
async extract() {
|
|
2532
|
-
const ctx = this.
|
|
2638
|
+
const ctx = this.getContextOrThrow();
|
|
2533
2639
|
const done = import_logger4.logger.time.info("Extracted in");
|
|
2534
|
-
await Promise.all(
|
|
2535
|
-
ctx.getFiles().map(async (file) => {
|
|
2536
|
-
const mtime = (0, import_fs.existsSync)(file) ? (0, import_fs_extra2.statSync)(file).mtimeMs : -Infinity;
|
|
2537
|
-
const isUnchanged = this.fileModifiedMap.has(file) && mtime === this.fileModifiedMap.get(file);
|
|
2538
|
-
if (isUnchanged)
|
|
2539
|
-
return;
|
|
2540
|
-
const css = extractFile(ctx, file);
|
|
2541
|
-
if (!css)
|
|
2542
|
-
return;
|
|
2543
|
-
this.fileModifiedMap.set(file, mtime);
|
|
2544
|
-
this.writeFile(file, css);
|
|
2545
|
-
return css;
|
|
2546
|
-
})
|
|
2547
|
-
);
|
|
2640
|
+
await Promise.all(ctx.getFiles().map((file) => this.extractFile(ctx, file)));
|
|
2548
2641
|
done();
|
|
2549
2642
|
}
|
|
2550
2643
|
toString() {
|
|
2551
|
-
const ctx = this.
|
|
2644
|
+
const ctx = this.getContextOrThrow();
|
|
2552
2645
|
return ctx.getCss({
|
|
2553
2646
|
files: Array.from(this.fileCssMap.values()),
|
|
2554
2647
|
resolve: true
|
|
@@ -2576,7 +2669,7 @@ var Builder = class {
|
|
|
2576
2669
|
);
|
|
2577
2670
|
}
|
|
2578
2671
|
registerDependency(fn) {
|
|
2579
|
-
const ctx = this.
|
|
2672
|
+
const ctx = this.getContextOrThrow();
|
|
2580
2673
|
for (const fileOrGlob of ctx.config.include) {
|
|
2581
2674
|
const dependency = parseDependency(fileOrGlob);
|
|
2582
2675
|
if (dependency) {
|
|
@@ -2584,7 +2677,7 @@ var Builder = class {
|
|
|
2584
2677
|
}
|
|
2585
2678
|
}
|
|
2586
2679
|
for (const file of ctx.dependencies) {
|
|
2587
|
-
fn({ type: "dependency", file: (0,
|
|
2680
|
+
fn({ type: "dependency", file: (0, import_path4.resolve)(file) });
|
|
2588
2681
|
}
|
|
2589
2682
|
}
|
|
2590
2683
|
};
|
|
@@ -2593,7 +2686,7 @@ var Builder = class {
|
|
|
2593
2686
|
init_cjs_shims();
|
|
2594
2687
|
var import_logger5 = require("@pandacss/logger");
|
|
2595
2688
|
var import_promises2 = require("fs/promises");
|
|
2596
|
-
var
|
|
2689
|
+
var path2 = __toESM(require("path"));
|
|
2597
2690
|
async function debugFiles(ctx, options) {
|
|
2598
2691
|
const files = ctx.getFiles();
|
|
2599
2692
|
const measureTotal = import_logger5.logger.time.debug(`Done parsing ${files.length} files`);
|
|
@@ -2633,10 +2726,10 @@ async function debugFiles(ctx, options) {
|
|
|
2633
2726
|
}
|
|
2634
2727
|
if (options.outdir) {
|
|
2635
2728
|
filesWithCss.push(file);
|
|
2636
|
-
const parsedPath =
|
|
2637
|
-
const relative3 =
|
|
2638
|
-
const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(
|
|
2639
|
-
const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(
|
|
2729
|
+
const parsedPath = path2.parse(file);
|
|
2730
|
+
const relative3 = path2.relative(ctx.config.cwd, parsedPath.dir);
|
|
2731
|
+
const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
|
|
2732
|
+
const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
|
|
2640
2733
|
import_logger5.logger.info("cli", `Writing ${import_logger5.colors.bold(`${options.outdir}/${astJsonPath}`)}`);
|
|
2641
2734
|
import_logger5.logger.info("cli", `Writing ${import_logger5.colors.bold(`${options.outdir}/${cssPath}`)}`);
|
|
2642
2735
|
return Promise.all([
|
|
@@ -2704,22 +2797,22 @@ async function generate(config, configPath) {
|
|
|
2704
2797
|
const ctx = ctxRef.current;
|
|
2705
2798
|
await build(ctx);
|
|
2706
2799
|
const {
|
|
2707
|
-
runtime: { fs:
|
|
2800
|
+
runtime: { fs: fs3, path: path3 },
|
|
2708
2801
|
dependencies,
|
|
2709
2802
|
config: { cwd }
|
|
2710
2803
|
} = ctx;
|
|
2711
2804
|
if (ctx.config.watch) {
|
|
2712
|
-
const configWatcher =
|
|
2805
|
+
const configWatcher = fs3.watch({ include: dependencies });
|
|
2713
2806
|
configWatcher.on("change", async () => {
|
|
2714
2807
|
import_logger7.logger.info("config:change", "Config changed, restarting...");
|
|
2715
2808
|
await loadCtx();
|
|
2716
2809
|
return build(ctxRef.current);
|
|
2717
2810
|
});
|
|
2718
|
-
const contentWatcher =
|
|
2811
|
+
const contentWatcher = fs3.watch(ctx.config);
|
|
2719
2812
|
contentWatcher.on("all", async (event, file) => {
|
|
2720
2813
|
import_logger7.logger.info(`file:${event}`, file);
|
|
2721
2814
|
(0, import_ts_pattern.match)(event).with("unlink", () => {
|
|
2722
|
-
ctx.project.removeSourceFile(
|
|
2815
|
+
ctx.project.removeSourceFile(path3.abs(cwd, file));
|
|
2723
2816
|
ctx.chunks.rm(file);
|
|
2724
2817
|
}).with("change", async () => {
|
|
2725
2818
|
ctx.project.reloadSourceFile(file);
|
|
@@ -2737,7 +2830,7 @@ async function generate(config, configPath) {
|
|
|
2737
2830
|
|
|
2738
2831
|
// src/git-ignore.ts
|
|
2739
2832
|
init_cjs_shims();
|
|
2740
|
-
var
|
|
2833
|
+
var import_fs3 = require("fs");
|
|
2741
2834
|
var import_look_it_up2 = require("look-it-up");
|
|
2742
2835
|
var import_outdent = __toESM(require("outdent"));
|
|
2743
2836
|
function setupGitIgnore({ config: { outdir, gitignore = true } }) {
|
|
@@ -2749,11 +2842,11 @@ function setupGitIgnore({ config: { outdir, gitignore = true } }) {
|
|
|
2749
2842
|
`;
|
|
2750
2843
|
const file = (0, import_look_it_up2.lookItUpSync)(".gitignore");
|
|
2751
2844
|
if (!file) {
|
|
2752
|
-
return (0,
|
|
2845
|
+
return (0, import_fs3.writeFileSync)(".gitignore", txt);
|
|
2753
2846
|
}
|
|
2754
|
-
const content = (0,
|
|
2847
|
+
const content = (0, import_fs3.readFileSync)(file, "utf-8");
|
|
2755
2848
|
if (!content.includes(outdir)) {
|
|
2756
|
-
(0,
|
|
2849
|
+
(0, import_fs3.appendFileSync)(file, txt);
|
|
2757
2850
|
}
|
|
2758
2851
|
}
|
|
2759
2852
|
|
|
@@ -2764,7 +2857,7 @@ var import_generator2 = require("@pandacss/generator");
|
|
|
2764
2857
|
var import_fs_extra3 = require("fs-extra");
|
|
2765
2858
|
var import_look_it_up3 = require("look-it-up");
|
|
2766
2859
|
var import_outdent2 = require("outdent");
|
|
2767
|
-
var
|
|
2860
|
+
var import_path5 = require("path");
|
|
2768
2861
|
var import_preferred_pm2 = __toESM(require("preferred-pm"));
|
|
2769
2862
|
async function setupConfig(cwd, { force }) {
|
|
2770
2863
|
const configFile = findConfig();
|
|
@@ -2794,7 +2887,7 @@ async function setupConfig(cwd, { force }) {
|
|
|
2794
2887
|
outdir: "styled-system",
|
|
2795
2888
|
})
|
|
2796
2889
|
`;
|
|
2797
|
-
await (0, import_fs_extra3.writeFile)((0,
|
|
2890
|
+
await (0, import_fs_extra3.writeFile)((0, import_path5.join)(cwd, file), content);
|
|
2798
2891
|
import_logger8.logger.log(import_generator2.messages.thankYou());
|
|
2799
2892
|
}
|
|
2800
2893
|
}
|
|
@@ -2807,7 +2900,7 @@ async function setupPostcss(cwd) {
|
|
|
2807
2900
|
},
|
|
2808
2901
|
}
|
|
2809
2902
|
`;
|
|
2810
|
-
await (0, import_fs_extra3.writeFile)((0,
|
|
2903
|
+
await (0, import_fs_extra3.writeFile)((0, import_path5.join)(cwd, "postcss.config.cjs"), content);
|
|
2811
2904
|
}
|
|
2812
2905
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2813
2906
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -865,8 +865,7 @@ init_esm_shims();
|
|
|
865
865
|
import { discardDuplicate, mergeCss as mergeCss2 } from "@pandacss/core";
|
|
866
866
|
import { ConfigNotFoundError } from "@pandacss/error";
|
|
867
867
|
import { logger as logger4 } from "@pandacss/logger";
|
|
868
|
-
import {
|
|
869
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
868
|
+
import { existsSync as existsSync2 } from "fs";
|
|
870
869
|
import { statSync } from "fs-extra";
|
|
871
870
|
import { resolve as resolve2 } from "path";
|
|
872
871
|
|
|
@@ -884,18 +883,18 @@ import { Obj, pipe, tap } from "lil-fp";
|
|
|
884
883
|
// src/chunk-engine.ts
|
|
885
884
|
init_esm_shims();
|
|
886
885
|
import { mergeCss } from "@pandacss/core";
|
|
887
|
-
var getChunkEngine = ({ paths, config, runtime: { path:
|
|
888
|
-
dir:
|
|
886
|
+
var getChunkEngine = ({ paths, config, runtime: { path: path3, fs: fs2 } }) => ({
|
|
887
|
+
dir: path3.join(...paths.chunk),
|
|
889
888
|
readFile(file) {
|
|
890
|
-
const fileName =
|
|
891
|
-
return
|
|
889
|
+
const fileName = path3.join(...paths.chunk, this.format(file));
|
|
890
|
+
return fs2.existsSync(fileName) ? fs2.readFileSync(fileName) : "";
|
|
892
891
|
},
|
|
893
892
|
getFiles() {
|
|
894
|
-
const files =
|
|
895
|
-
return files.map((file) =>
|
|
893
|
+
const files = fs2.existsSync(this.dir) ? fs2.readDirSync(this.dir) : [];
|
|
894
|
+
return files.map((file) => fs2.readFileSync(path3.join(this.dir, file)));
|
|
896
895
|
},
|
|
897
896
|
format(file) {
|
|
898
|
-
return
|
|
897
|
+
return path3.relative(config.cwd, file).replaceAll(path3.sep, "__").replace(path3.extname(file), ".css");
|
|
899
898
|
},
|
|
900
899
|
getArtifact(file, css) {
|
|
901
900
|
const fileName = this.format(file);
|
|
@@ -906,10 +905,10 @@ var getChunkEngine = ({ paths, config, runtime: { path: path2, fs } }) => ({
|
|
|
906
905
|
};
|
|
907
906
|
},
|
|
908
907
|
rm(file) {
|
|
909
|
-
return
|
|
908
|
+
return fs2.rmFileSync(path3.join(...paths.chunk, this.format(file)));
|
|
910
909
|
},
|
|
911
910
|
empty() {
|
|
912
|
-
return
|
|
911
|
+
return fs2.rmDirSync(this.dir);
|
|
913
912
|
},
|
|
914
913
|
get glob() {
|
|
915
914
|
return [`${this.dir}/**/*.css`];
|
|
@@ -965,8 +964,8 @@ var nodeRuntime = {
|
|
|
965
964
|
readDirSync: readdirSync,
|
|
966
965
|
rmDirSync: emptyDirSync,
|
|
967
966
|
rmFileSync: removeSync,
|
|
968
|
-
ensureDirSync(
|
|
969
|
-
return ensureDirSync(
|
|
967
|
+
ensureDirSync(path3) {
|
|
968
|
+
return ensureDirSync(path3);
|
|
970
969
|
},
|
|
971
970
|
watch(options) {
|
|
972
971
|
const { include, exclude, cwd, poll } = options;
|
|
@@ -997,20 +996,20 @@ process.on("uncaughtException", (reason) => {
|
|
|
997
996
|
|
|
998
997
|
// src/output-engine.ts
|
|
999
998
|
init_esm_shims();
|
|
1000
|
-
var getOutputEngine = ({ paths, runtime: { path:
|
|
999
|
+
var getOutputEngine = ({ paths, runtime: { path: path3, fs: fs2 } }) => ({
|
|
1001
1000
|
empty() {
|
|
1002
|
-
|
|
1001
|
+
fs2.rmDirSync(path3.join(...paths.root));
|
|
1003
1002
|
},
|
|
1004
1003
|
async write(output) {
|
|
1005
1004
|
if (!output)
|
|
1006
1005
|
return;
|
|
1007
1006
|
const { dir = paths.root, files } = output;
|
|
1008
|
-
|
|
1007
|
+
fs2.ensureDirSync(path3.join(...dir));
|
|
1009
1008
|
return Promise.all(
|
|
1010
1009
|
files.map(async ({ file, code }) => {
|
|
1011
|
-
const absPath =
|
|
1010
|
+
const absPath = path3.join(...dir, file);
|
|
1012
1011
|
if (code) {
|
|
1013
|
-
return
|
|
1012
|
+
return fs2.writeFile(absPath, code);
|
|
1014
1013
|
}
|
|
1015
1014
|
})
|
|
1016
1015
|
);
|
|
@@ -1025,14 +1024,14 @@ var createContext = (conf) => pipe(
|
|
|
1025
1024
|
tap(({ config, runtime }) => {
|
|
1026
1025
|
config.cwd ||= runtime.cwd();
|
|
1027
1026
|
}),
|
|
1028
|
-
Obj.bind("getFiles", ({ config, runtime: { fs } }) => () => {
|
|
1027
|
+
Obj.bind("getFiles", ({ config, runtime: { fs: fs2 } }) => () => {
|
|
1029
1028
|
const { include, exclude, cwd } = config;
|
|
1030
|
-
return
|
|
1029
|
+
return fs2.glob({ include, exclude, cwd });
|
|
1031
1030
|
}),
|
|
1032
|
-
Obj.bind("project", ({ getFiles, runtime: { fs }, parserOptions }) => {
|
|
1031
|
+
Obj.bind("project", ({ getFiles, runtime: { fs: fs2 }, parserOptions }) => {
|
|
1033
1032
|
return createProject({
|
|
1034
1033
|
getFiles,
|
|
1035
|
-
readFile:
|
|
1034
|
+
readFile: fs2.readFileSync,
|
|
1036
1035
|
parserOptions
|
|
1037
1036
|
});
|
|
1038
1037
|
}),
|
|
@@ -2365,8 +2364,8 @@ async function bundleChunks(ctx) {
|
|
|
2365
2364
|
});
|
|
2366
2365
|
}
|
|
2367
2366
|
async function writeFileChunk(ctx, file) {
|
|
2368
|
-
const { path:
|
|
2369
|
-
logger3.debug("chunk:write", `File: ${
|
|
2367
|
+
const { path: path3 } = ctx.runtime;
|
|
2368
|
+
logger3.debug("chunk:write", `File: ${path3.relative(ctx.config.cwd, file)}`);
|
|
2370
2369
|
const css = extractFile(ctx, file);
|
|
2371
2370
|
if (!css)
|
|
2372
2371
|
return;
|
|
@@ -2375,11 +2374,11 @@ async function writeFileChunk(ctx, file) {
|
|
|
2375
2374
|
}
|
|
2376
2375
|
function extractFile(ctx, file) {
|
|
2377
2376
|
const {
|
|
2378
|
-
runtime: { path:
|
|
2377
|
+
runtime: { path: path3 },
|
|
2379
2378
|
config: { cwd }
|
|
2380
2379
|
} = ctx;
|
|
2381
2380
|
return pipe2(
|
|
2382
|
-
{ file:
|
|
2381
|
+
{ file: path3.abs(cwd, file) },
|
|
2383
2382
|
tap2(() => logger3.debug("file:extract", file)),
|
|
2384
2383
|
Obj2.bind("measure", () => logger3.time.debug(`Extracted ${file}`)),
|
|
2385
2384
|
Obj2.bind(
|
|
@@ -2421,6 +2420,58 @@ async function extractCss(ctx) {
|
|
|
2421
2420
|
return ctx.messages.buildComplete(ctx.getFiles().length);
|
|
2422
2421
|
}
|
|
2423
2422
|
|
|
2423
|
+
// src/get-mod-deps.ts
|
|
2424
|
+
init_esm_shims();
|
|
2425
|
+
import fs from "fs";
|
|
2426
|
+
import path from "path";
|
|
2427
|
+
var jsExtensions = [".js", ".cjs", ".mjs"];
|
|
2428
|
+
var jsResolutionOrder = ["", ".js", ".cjs", ".mjs", ".ts", ".cts", ".mts", ".jsx", ".tsx"];
|
|
2429
|
+
var tsResolutionOrder = ["", ".ts", ".cts", ".mts", ".tsx", ".js", ".cjs", ".mjs", ".jsx"];
|
|
2430
|
+
function resolveWithExtension(file, extensions) {
|
|
2431
|
+
for (const ext of extensions) {
|
|
2432
|
+
const full = `${file}${ext}`;
|
|
2433
|
+
if (fs.existsSync(full) && fs.statSync(full).isFile()) {
|
|
2434
|
+
return full;
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
for (const ext of extensions) {
|
|
2438
|
+
const full = `${file}/index${ext}`;
|
|
2439
|
+
if (fs.existsSync(full)) {
|
|
2440
|
+
return full;
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
return null;
|
|
2444
|
+
}
|
|
2445
|
+
function* getDeps(filename, base, seen, ext = path.extname(filename)) {
|
|
2446
|
+
const absoluteFile = resolveWithExtension(
|
|
2447
|
+
path.resolve(base, filename),
|
|
2448
|
+
jsExtensions.includes(ext) ? jsResolutionOrder : tsResolutionOrder
|
|
2449
|
+
);
|
|
2450
|
+
if (absoluteFile === null)
|
|
2451
|
+
return;
|
|
2452
|
+
if (seen.has(absoluteFile))
|
|
2453
|
+
return;
|
|
2454
|
+
seen.add(absoluteFile);
|
|
2455
|
+
yield absoluteFile;
|
|
2456
|
+
base = path.dirname(absoluteFile);
|
|
2457
|
+
ext = path.extname(absoluteFile);
|
|
2458
|
+
const contents = fs.readFileSync(absoluteFile, "utf-8");
|
|
2459
|
+
for (const match2 of [
|
|
2460
|
+
...contents.matchAll(/import[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
2461
|
+
...contents.matchAll(/import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
2462
|
+
...contents.matchAll(/require\(['"`](.+)['"`]\)/gi)
|
|
2463
|
+
]) {
|
|
2464
|
+
if (!match2[1].startsWith("."))
|
|
2465
|
+
continue;
|
|
2466
|
+
yield* getDeps(match2[1], base, seen, ext);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
function getModuleDependencies(filePath) {
|
|
2470
|
+
if (filePath === null)
|
|
2471
|
+
return /* @__PURE__ */ new Set();
|
|
2472
|
+
return new Set(getDeps(filePath, path.dirname(filePath), /* @__PURE__ */ new Set()));
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2424
2475
|
// src/parse-dependency.ts
|
|
2425
2476
|
init_esm_shims();
|
|
2426
2477
|
import isGlob from "is-glob";
|
|
@@ -2466,78 +2517,120 @@ function parseDependency(fileOrGlob) {
|
|
|
2466
2517
|
}
|
|
2467
2518
|
|
|
2468
2519
|
// src/builder.ts
|
|
2469
|
-
var
|
|
2470
|
-
var
|
|
2471
|
-
function getConfigHash() {
|
|
2472
|
-
const file = findConfig();
|
|
2473
|
-
if (!file) {
|
|
2474
|
-
throw new ConfigNotFoundError();
|
|
2475
|
-
}
|
|
2476
|
-
return toHash(readFileSync2(file, "utf-8"));
|
|
2477
|
-
}
|
|
2520
|
+
var configCache = /* @__PURE__ */ new Map();
|
|
2521
|
+
var contentFilesCache = /* @__PURE__ */ new WeakMap();
|
|
2478
2522
|
var setupCount = 0;
|
|
2479
2523
|
var Builder = class {
|
|
2480
2524
|
/**
|
|
2481
|
-
*
|
|
2525
|
+
* The current panda context
|
|
2482
2526
|
*/
|
|
2483
|
-
fileModifiedMap = /* @__PURE__ */ new Map();
|
|
2484
|
-
/**
|
|
2485
|
-
* Map of file path to css
|
|
2486
|
-
*/
|
|
2487
|
-
fileCssMap = /* @__PURE__ */ new Map();
|
|
2488
2527
|
context;
|
|
2489
|
-
|
|
2490
|
-
writeFile(file, css) {
|
|
2528
|
+
writeFileCss(file, css) {
|
|
2491
2529
|
const oldCss = this.fileCssMap?.get(file) ?? "";
|
|
2492
2530
|
const newCss = mergeCss2(oldCss, css);
|
|
2493
2531
|
this.fileCssMap?.set(file, newCss);
|
|
2494
2532
|
}
|
|
2533
|
+
checkConfigDeps(configPath, deps) {
|
|
2534
|
+
let modified = false;
|
|
2535
|
+
const newModified = /* @__PURE__ */ new Map();
|
|
2536
|
+
const prevModified = configCache.get(configPath)?.depsModifiedMap;
|
|
2537
|
+
for (const file of deps) {
|
|
2538
|
+
const time = statSync(file).mtimeMs;
|
|
2539
|
+
newModified.set(file, time);
|
|
2540
|
+
if (!prevModified || !prevModified.has(file) || time > prevModified.get(file)) {
|
|
2541
|
+
modified = true;
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
if (!modified) {
|
|
2545
|
+
return { isModified: false, modifiedMap: prevModified };
|
|
2546
|
+
}
|
|
2547
|
+
for (const file of deps) {
|
|
2548
|
+
delete __require.cache[file];
|
|
2549
|
+
}
|
|
2550
|
+
if (setupCount > 0) {
|
|
2551
|
+
logger4.info("postcss", "\u2699\uFE0F Config changed, reloading");
|
|
2552
|
+
}
|
|
2553
|
+
return { isModified: true, modifiedMap: newModified };
|
|
2554
|
+
}
|
|
2555
|
+
getConfigPath() {
|
|
2556
|
+
const configPath = findConfig();
|
|
2557
|
+
if (!configPath) {
|
|
2558
|
+
throw new ConfigNotFoundError();
|
|
2559
|
+
}
|
|
2560
|
+
return configPath;
|
|
2561
|
+
}
|
|
2495
2562
|
async setup() {
|
|
2496
|
-
const
|
|
2497
|
-
const
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
this.
|
|
2501
|
-
|
|
2502
|
-
|
|
2563
|
+
const configPath = this.getConfigPath();
|
|
2564
|
+
const configDeps = getModuleDependencies(configPath);
|
|
2565
|
+
const deps = this.checkConfigDeps(configPath, configDeps);
|
|
2566
|
+
if (deps.isModified) {
|
|
2567
|
+
return this.setupContext({
|
|
2568
|
+
configPath,
|
|
2569
|
+
depsModifiedMap: deps.modifiedMap
|
|
2570
|
+
});
|
|
2571
|
+
}
|
|
2572
|
+
const cache = configCache.get(configPath);
|
|
2573
|
+
if (cache) {
|
|
2574
|
+
this.context = cache.context;
|
|
2575
|
+
this.context.project.reloadSourceFiles();
|
|
2503
2576
|
} else {
|
|
2504
|
-
this.
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
}
|
|
2508
|
-
this.fileCssMap = /* @__PURE__ */ new Map();
|
|
2509
|
-
this.fileModifiedMap = /* @__PURE__ */ new Map();
|
|
2510
|
-
contextCache.set(configHash, this.context);
|
|
2511
|
-
builderCache.set(this.context, { fileCssMap: this.fileCssMap, fileModifiedMap: this.fileModifiedMap });
|
|
2577
|
+
await this.setupContext({
|
|
2578
|
+
configPath,
|
|
2579
|
+
depsModifiedMap: deps.modifiedMap
|
|
2580
|
+
});
|
|
2512
2581
|
}
|
|
2513
2582
|
setupCount++;
|
|
2514
2583
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2584
|
+
async setupContext(options) {
|
|
2585
|
+
const { configPath, depsModifiedMap } = options;
|
|
2586
|
+
this.context = await loadConfigAndCreateContext({ configPath });
|
|
2587
|
+
if (setupCount > 0) {
|
|
2588
|
+
emitArtifacts(this.context);
|
|
2589
|
+
}
|
|
2590
|
+
configCache.set(configPath, {
|
|
2591
|
+
context: this.context,
|
|
2592
|
+
deps: new Set(this.context.configDependencies),
|
|
2593
|
+
depsModifiedMap
|
|
2594
|
+
});
|
|
2595
|
+
contentFilesCache.set(this.context, {
|
|
2596
|
+
fileCssMap: /* @__PURE__ */ new Map(),
|
|
2597
|
+
fileModifiedMap: /* @__PURE__ */ new Map()
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
getContextOrThrow() {
|
|
2601
|
+
if (!this.context) {
|
|
2517
2602
|
throw new Error("context not loaded");
|
|
2603
|
+
}
|
|
2518
2604
|
return this.context;
|
|
2519
2605
|
}
|
|
2606
|
+
get fileModifiedMap() {
|
|
2607
|
+
const ctx = this.getContextOrThrow();
|
|
2608
|
+
return contentFilesCache.get(ctx).fileModifiedMap;
|
|
2609
|
+
}
|
|
2610
|
+
get fileCssMap() {
|
|
2611
|
+
const ctx = this.getContextOrThrow();
|
|
2612
|
+
return contentFilesCache.get(ctx).fileCssMap;
|
|
2613
|
+
}
|
|
2614
|
+
async extractFile(ctx, file) {
|
|
2615
|
+
const mtime = existsSync2(file) ? statSync(file).mtimeMs : -Infinity;
|
|
2616
|
+
const isUnchanged = this.fileModifiedMap.has(file) && mtime === this.fileModifiedMap.get(file);
|
|
2617
|
+
if (isUnchanged)
|
|
2618
|
+
return;
|
|
2619
|
+
const css = extractFile(ctx, file);
|
|
2620
|
+
if (!css)
|
|
2621
|
+
return;
|
|
2622
|
+
this.fileModifiedMap.set(file, mtime);
|
|
2623
|
+
this.writeFileCss(file, css);
|
|
2624
|
+
return css;
|
|
2625
|
+
}
|
|
2520
2626
|
async extract() {
|
|
2521
|
-
const ctx = this.
|
|
2627
|
+
const ctx = this.getContextOrThrow();
|
|
2522
2628
|
const done = logger4.time.info("Extracted in");
|
|
2523
|
-
await Promise.all(
|
|
2524
|
-
ctx.getFiles().map(async (file) => {
|
|
2525
|
-
const mtime = existsSync2(file) ? statSync(file).mtimeMs : -Infinity;
|
|
2526
|
-
const isUnchanged = this.fileModifiedMap.has(file) && mtime === this.fileModifiedMap.get(file);
|
|
2527
|
-
if (isUnchanged)
|
|
2528
|
-
return;
|
|
2529
|
-
const css = extractFile(ctx, file);
|
|
2530
|
-
if (!css)
|
|
2531
|
-
return;
|
|
2532
|
-
this.fileModifiedMap.set(file, mtime);
|
|
2533
|
-
this.writeFile(file, css);
|
|
2534
|
-
return css;
|
|
2535
|
-
})
|
|
2536
|
-
);
|
|
2629
|
+
await Promise.all(ctx.getFiles().map((file) => this.extractFile(ctx, file)));
|
|
2537
2630
|
done();
|
|
2538
2631
|
}
|
|
2539
2632
|
toString() {
|
|
2540
|
-
const ctx = this.
|
|
2633
|
+
const ctx = this.getContextOrThrow();
|
|
2541
2634
|
return ctx.getCss({
|
|
2542
2635
|
files: Array.from(this.fileCssMap.values()),
|
|
2543
2636
|
resolve: true
|
|
@@ -2565,7 +2658,7 @@ var Builder = class {
|
|
|
2565
2658
|
);
|
|
2566
2659
|
}
|
|
2567
2660
|
registerDependency(fn) {
|
|
2568
|
-
const ctx = this.
|
|
2661
|
+
const ctx = this.getContextOrThrow();
|
|
2569
2662
|
for (const fileOrGlob of ctx.config.include) {
|
|
2570
2663
|
const dependency = parseDependency(fileOrGlob);
|
|
2571
2664
|
if (dependency) {
|
|
@@ -2582,7 +2675,7 @@ var Builder = class {
|
|
|
2582
2675
|
init_esm_shims();
|
|
2583
2676
|
import { colors, logger as logger5 } from "@pandacss/logger";
|
|
2584
2677
|
import { mkdir, writeFile as writeFile3 } from "fs/promises";
|
|
2585
|
-
import * as
|
|
2678
|
+
import * as path2 from "path";
|
|
2586
2679
|
async function debugFiles(ctx, options) {
|
|
2587
2680
|
const files = ctx.getFiles();
|
|
2588
2681
|
const measureTotal = logger5.time.debug(`Done parsing ${files.length} files`);
|
|
@@ -2622,10 +2715,10 @@ async function debugFiles(ctx, options) {
|
|
|
2622
2715
|
}
|
|
2623
2716
|
if (options.outdir) {
|
|
2624
2717
|
filesWithCss.push(file);
|
|
2625
|
-
const parsedPath =
|
|
2626
|
-
const relative3 =
|
|
2627
|
-
const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(
|
|
2628
|
-
const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(
|
|
2718
|
+
const parsedPath = path2.parse(file);
|
|
2719
|
+
const relative3 = path2.relative(ctx.config.cwd, parsedPath.dir);
|
|
2720
|
+
const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
|
|
2721
|
+
const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
|
|
2629
2722
|
logger5.info("cli", `Writing ${colors.bold(`${options.outdir}/${astJsonPath}`)}`);
|
|
2630
2723
|
logger5.info("cli", `Writing ${colors.bold(`${options.outdir}/${cssPath}`)}`);
|
|
2631
2724
|
return Promise.all([
|
|
@@ -2693,22 +2786,22 @@ async function generate(config, configPath) {
|
|
|
2693
2786
|
const ctx = ctxRef.current;
|
|
2694
2787
|
await build(ctx);
|
|
2695
2788
|
const {
|
|
2696
|
-
runtime: { fs, path:
|
|
2789
|
+
runtime: { fs: fs2, path: path3 },
|
|
2697
2790
|
dependencies,
|
|
2698
2791
|
config: { cwd }
|
|
2699
2792
|
} = ctx;
|
|
2700
2793
|
if (ctx.config.watch) {
|
|
2701
|
-
const configWatcher =
|
|
2794
|
+
const configWatcher = fs2.watch({ include: dependencies });
|
|
2702
2795
|
configWatcher.on("change", async () => {
|
|
2703
2796
|
logger7.info("config:change", "Config changed, restarting...");
|
|
2704
2797
|
await loadCtx();
|
|
2705
2798
|
return build(ctxRef.current);
|
|
2706
2799
|
});
|
|
2707
|
-
const contentWatcher =
|
|
2800
|
+
const contentWatcher = fs2.watch(ctx.config);
|
|
2708
2801
|
contentWatcher.on("all", async (event, file) => {
|
|
2709
2802
|
logger7.info(`file:${event}`, file);
|
|
2710
2803
|
match(event).with("unlink", () => {
|
|
2711
|
-
ctx.project.removeSourceFile(
|
|
2804
|
+
ctx.project.removeSourceFile(path3.abs(cwd, file));
|
|
2712
2805
|
ctx.chunks.rm(file);
|
|
2713
2806
|
}).with("change", async () => {
|
|
2714
2807
|
ctx.project.reloadSourceFile(file);
|
|
@@ -2726,7 +2819,7 @@ async function generate(config, configPath) {
|
|
|
2726
2819
|
|
|
2727
2820
|
// src/git-ignore.ts
|
|
2728
2821
|
init_esm_shims();
|
|
2729
|
-
import { appendFileSync, readFileSync as
|
|
2822
|
+
import { appendFileSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
2730
2823
|
import { lookItUpSync as lookItUpSync2 } from "look-it-up";
|
|
2731
2824
|
import outdent from "outdent";
|
|
2732
2825
|
function setupGitIgnore({ config: { outdir, gitignore = true } }) {
|
|
@@ -2740,7 +2833,7 @@ function setupGitIgnore({ config: { outdir, gitignore = true } }) {
|
|
|
2740
2833
|
if (!file) {
|
|
2741
2834
|
return writeFileSync2(".gitignore", txt);
|
|
2742
2835
|
}
|
|
2743
|
-
const content =
|
|
2836
|
+
const content = readFileSync2(file, "utf-8");
|
|
2744
2837
|
if (!content.includes(outdir)) {
|
|
2745
2838
|
appendFileSync(file, txt);
|
|
2746
2839
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/node",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20230515185702",
|
|
4
4
|
"description": "The core css panda library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"preferred-pm": "^3.0.3",
|
|
34
34
|
"ts-morph": "18.0.0",
|
|
35
35
|
"ts-pattern": "4.3.0",
|
|
36
|
-
"@pandacss/config": "0.0.0-dev-
|
|
37
|
-
"@pandacss/core": "0.0.0-dev-
|
|
38
|
-
"@pandacss/error": "0.0.0-dev-
|
|
39
|
-
"@pandacss/generator": "0.0.0-dev-
|
|
40
|
-
"@pandacss/is-valid-prop": "0.0.0-dev-
|
|
41
|
-
"@pandacss/logger": "0.0.0-dev-
|
|
42
|
-
"@pandacss/parser": "0.0.0-dev-
|
|
43
|
-
"@pandacss/extractor": "0.0.0-dev-
|
|
44
|
-
"@pandacss/shared": "0.0.0-dev-
|
|
45
|
-
"@pandacss/token-dictionary": "0.0.0-dev-
|
|
46
|
-
"@pandacss/types": "0.0.0-dev-
|
|
36
|
+
"@pandacss/config": "0.0.0-dev-20230515185702",
|
|
37
|
+
"@pandacss/core": "0.0.0-dev-20230515185702",
|
|
38
|
+
"@pandacss/error": "0.0.0-dev-20230515185702",
|
|
39
|
+
"@pandacss/generator": "0.0.0-dev-20230515185702",
|
|
40
|
+
"@pandacss/is-valid-prop": "0.0.0-dev-20230515185702",
|
|
41
|
+
"@pandacss/logger": "0.0.0-dev-20230515185702",
|
|
42
|
+
"@pandacss/parser": "0.0.0-dev-20230515185702",
|
|
43
|
+
"@pandacss/extractor": "0.0.0-dev-20230515185702",
|
|
44
|
+
"@pandacss/shared": "0.0.0-dev-20230515185702",
|
|
45
|
+
"@pandacss/token-dictionary": "0.0.0-dev-20230515185702",
|
|
46
|
+
"@pandacss/types": "0.0.0-dev-20230515185702"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/fs-extra": "11.0.1",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/pluralize": "0.0.29",
|
|
54
54
|
"boxen": "^7.1.0",
|
|
55
55
|
"gzip-size": "^7.0.0",
|
|
56
|
-
"@pandacss/fixture": "0.0.0-dev-
|
|
56
|
+
"@pandacss/fixture": "0.0.0-dev-20230515185702"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup src/index.ts --format=cjs,esm --shims --dts",
|