@pandacss/node 0.0.0-dev-20230530090525 → 0.0.0-dev-20230530140607

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  export { discardDuplicate } from '@pandacss/core';
2
2
  import * as _pandacss_types from '@pandacss/types';
3
- import { Artifact, LoadConfigResult, ParserResult, Config } from '@pandacss/types';
3
+ import { Artifact, LoadConfigResult, ParserResultType, Config } from '@pandacss/types';
4
4
  import { Generator } from '@pandacss/generator';
5
5
  import { Project } from '@pandacss/parser';
6
6
  import { Runtime } from '@pandacss/types/src/runtime';
@@ -36,7 +36,7 @@ type PandaContext = Generator & {
36
36
  };
37
37
 
38
38
  declare function analyzeTokens(ctx: PandaContext, options?: {
39
- onResult?: (file: string, result: ParserResult) => void;
39
+ onResult?: (file: string, result: ParserResultType) => void;
40
40
  }): {
41
41
  duration: {
42
42
  extractTimeByFiles: {
@@ -225,9 +225,13 @@ declare function generate(config: Config, configPath?: string): Promise<void>;
225
225
 
226
226
  declare function setupGitIgnore({ config: { outdir, gitignore } }: PandaContext): void;
227
227
 
228
- declare function setupConfig(cwd: string, { force }: {
228
+ type SetupOptions = {
229
+ outExtension?: string;
229
230
  force?: boolean;
230
- }): Promise<void>;
231
+ };
232
+ declare function setupConfig(cwd: string, opts?: SetupOptions): Promise<void>;
231
233
  declare function setupPostcss(cwd: string): Promise<void>;
232
234
 
233
- export { Builder, analyzeTokens, createContext, debugFiles, emitAndExtract, emitArtifacts, execCommand, extractCss, generate, loadConfigAndCreateContext, setupConfig, setupGitIgnore, setupPostcss, writeAnalyzeJSON };
235
+ declare function shipFiles(ctx: PandaContext, outfile: string): Promise<void>;
236
+
237
+ export { Builder, analyzeTokens, createContext, debugFiles, emitAndExtract, emitArtifacts, execCommand, extractCss, generate, loadConfigAndCreateContext, setupConfig, setupGitIgnore, setupPostcss, shipFiles, writeAnalyzeJSON };
package/dist/index.js CHANGED
@@ -489,6 +489,7 @@ __export(src_exports, {
489
489
  setupConfig: () => setupConfig,
490
490
  setupGitIgnore: () => setupGitIgnore,
491
491
  setupPostcss: () => setupPostcss,
492
+ shipFiles: () => shipFiles,
492
493
  writeAnalyzeJSON: () => writeAnalyzeJSON
493
494
  });
494
495
  module.exports = __toCommonJS(src_exports);
@@ -499,7 +500,6 @@ var import_core3 = require("@pandacss/core");
499
500
  init_cjs_shims();
500
501
  var import_logger = require("@pandacss/logger");
501
502
  var import_promises = require("fs/promises");
502
- var import_ts_morph = require("ts-morph");
503
503
 
504
504
  // src/classify.ts
505
505
  init_cjs_shims();
@@ -763,23 +763,6 @@ var getMostUsedInMap = (map, pickCount) => {
763
763
  return Array.from(map.entries()).map(([key, list]) => [key, list.size]).sort((a, b) => b[1] - a[1]).slice(0, pickCount).map(([key, count]) => ({ key, count }));
764
764
  };
765
765
 
766
- // src/get-node-range.ts
767
- init_cjs_shims();
768
- var getNodeRange = (node) => {
769
- const src = node.getSourceFile();
770
- const [startPosition, endPosition] = [node.getStart(), node.getEnd()];
771
- const startInfo = src.getLineAndColumnAtPos(startPosition);
772
- const endInfo = src.getLineAndColumnAtPos(endPosition);
773
- return {
774
- startPosition,
775
- startLineNumber: startInfo.line,
776
- startColumn: startInfo.column,
777
- endPosition,
778
- endLineNumber: endInfo.line,
779
- endColumn: endInfo.column
780
- };
781
- };
782
-
783
766
  // src/analyze-tokens.ts
784
767
  var import_filesize = require("filesize");
785
768
 
@@ -801,7 +784,7 @@ function analyzeTokens(ctx, options = {}) {
801
784
  const parserResultByFilepath = /* @__PURE__ */ new Map();
802
785
  const extractTimeByFilepath = /* @__PURE__ */ new Map();
803
786
  const includedFiles = ctx.getFiles();
804
- includedFiles.map((file) => {
787
+ includedFiles.forEach((file) => {
805
788
  const start2 = performance.now();
806
789
  const result = ctx.project.parseSourceFile(file);
807
790
  const extractMs = performance.now() - start2;
@@ -811,7 +794,6 @@ function analyzeTokens(ctx, options = {}) {
811
794
  parserResultByFilepath.set(file, result);
812
795
  options.onResult?.(file, result);
813
796
  }
814
- return [file, result];
815
797
  });
816
798
  const totalMs = Array.from(extractTimeByFilepath.values()).reduce((a, b) => a + b, 0);
817
799
  import_logger.logger.debug("analyze", `Analyzed ${includedFiles.length} files in ${totalMs.toFixed(2)}ms`);
@@ -854,14 +836,11 @@ var analyzeResultSerializer = (_key, value) => {
854
836
  if (value instanceof Map) {
855
837
  return Object.fromEntries(value);
856
838
  }
857
- if (import_ts_morph.Node.isNode(value)) {
858
- return { kind: value.getKindName(), range: getNodeRange(value) };
859
- }
860
839
  return value;
861
840
  };
862
841
  var writeAnalyzeJSON = (fileName, result, ctx) => {
863
842
  result.details.byInstanceId.forEach((item) => {
864
- item.box = { type: item.box.type, node: item.box.getNode(), stack: item.box.getStack() };
843
+ item.box = item.box.toJSON();
865
844
  });
866
845
  return (0, import_promises.writeFile)(
867
846
  fileName,
@@ -903,18 +882,18 @@ var import_lil_fp = require("lil-fp");
903
882
  // src/chunk-engine.ts
904
883
  init_cjs_shims();
905
884
  var import_core = require("@pandacss/core");
906
- var getChunkEngine = ({ paths, config, runtime: { path: path3, fs: fs3 } }) => ({
907
- dir: path3.join(...paths.chunk),
885
+ var getChunkEngine = ({ paths, config, runtime: { path: path4, fs: fs3 } }) => ({
886
+ dir: path4.join(...paths.chunk),
908
887
  readFile(file) {
909
- const fileName = path3.join(...paths.chunk, this.format(file));
888
+ const fileName = path4.join(...paths.chunk, this.format(file));
910
889
  return fs3.existsSync(fileName) ? fs3.readFileSync(fileName) : "";
911
890
  },
912
891
  getFiles() {
913
892
  const files = fs3.existsSync(this.dir) ? fs3.readDirSync(this.dir) : [];
914
- return files.map((file) => fs3.readFileSync(path3.join(this.dir, file)));
893
+ return files.map((file) => fs3.readFileSync(path4.join(this.dir, file)));
915
894
  },
916
895
  format(file) {
917
- return path3.relative(config.cwd, file).replaceAll(path3.sep, "__").replace(path3.extname(file), ".css");
896
+ return path4.relative(config.cwd, file).replaceAll(path4.sep, "__").replace(path4.extname(file), ".css");
918
897
  },
919
898
  getArtifact(file, css) {
920
899
  const fileName = this.format(file);
@@ -925,7 +904,7 @@ var getChunkEngine = ({ paths, config, runtime: { path: path3, fs: fs3 } }) => (
925
904
  };
926
905
  },
927
906
  rm(file) {
928
- return fs3.rmFileSync(path3.join(...paths.chunk, this.format(file)));
907
+ return fs3.rmFileSync(path4.join(...paths.chunk, this.format(file)));
929
908
  },
930
909
  empty() {
931
910
  return fs3.rmDirSync(this.dir);
@@ -975,8 +954,8 @@ var nodeRuntime = {
975
954
  readDirSync: import_fs_extra.readdirSync,
976
955
  rmDirSync: import_fs_extra.emptyDirSync,
977
956
  rmFileSync: import_fs_extra.removeSync,
978
- ensureDirSync(path3) {
979
- return (0, import_fs_extra.ensureDirSync)(path3);
957
+ ensureDirSync(path4) {
958
+ return (0, import_fs_extra.ensureDirSync)(path4);
980
959
  },
981
960
  watch(options) {
982
961
  const { include, exclude, cwd, poll } = options;
@@ -1007,18 +986,18 @@ process.on("uncaughtException", (reason) => {
1007
986
 
1008
987
  // src/output-engine.ts
1009
988
  init_cjs_shims();
1010
- var getOutputEngine = ({ paths, runtime: { path: path3, fs: fs3 } }) => ({
989
+ var getOutputEngine = ({ paths, runtime: { path: path4, fs: fs3 } }) => ({
1011
990
  empty() {
1012
- fs3.rmDirSync(path3.join(...paths.root));
991
+ fs3.rmDirSync(path4.join(...paths.root));
1013
992
  },
1014
993
  async write(output) {
1015
994
  if (!output)
1016
995
  return;
1017
996
  const { dir = paths.root, files } = output;
1018
- fs3.ensureDirSync(path3.join(...dir));
997
+ fs3.ensureDirSync(path4.join(...dir));
1019
998
  return Promise.all(
1020
999
  files.map(async ({ file, code }) => {
1021
- const absPath = path3.join(...dir, file);
1000
+ const absPath = path4.join(...dir, file);
1022
1001
  if (code) {
1023
1002
  return fs3.writeFile(absPath, code);
1024
1003
  }
@@ -2367,6 +2346,7 @@ var createBox = (options) => boxen(options.content, {
2367
2346
  });
2368
2347
 
2369
2348
  // src/extract.ts
2349
+ var import_parser2 = require("@pandacss/parser");
2370
2350
  async function bundleChunks(ctx) {
2371
2351
  const files = ctx.chunks.getFiles();
2372
2352
  return ctx.output.write({
@@ -2375,8 +2355,8 @@ async function bundleChunks(ctx) {
2375
2355
  });
2376
2356
  }
2377
2357
  async function writeFileChunk(ctx, file) {
2378
- const { path: path3 } = ctx.runtime;
2379
- import_logger3.logger.debug("chunk:write", `File: ${path3.relative(ctx.config.cwd, file)}`);
2358
+ const { path: path4 } = ctx.runtime;
2359
+ import_logger3.logger.debug("chunk:write", `File: ${path4.relative(ctx.config.cwd, file)}`);
2380
2360
  const css = extractFile(ctx, file);
2381
2361
  if (!css)
2382
2362
  return;
@@ -2385,17 +2365,19 @@ async function writeFileChunk(ctx, file) {
2385
2365
  }
2386
2366
  function extractFile(ctx, file) {
2387
2367
  const {
2388
- runtime: { path: path3 },
2368
+ runtime: { path: path4, fs: fs3 },
2389
2369
  config: { cwd }
2390
2370
  } = ctx;
2391
2371
  return (0, import_lil_fp2.pipe)(
2392
- { file: path3.abs(cwd, file) },
2372
+ { file: path4.abs(cwd, file) },
2393
2373
  (0, import_lil_fp2.tap)(() => import_logger3.logger.debug("file:extract", file)),
2394
2374
  import_lil_fp2.Obj.bind("measure", () => import_logger3.logger.time.debug(`Extracted ${file}`)),
2395
2375
  import_lil_fp2.Obj.bind(
2396
2376
  "result",
2397
2377
  (0, import_lil_fp2.tryCatch)(
2398
- ({ file: file2 }) => ctx.project.parseSourceFile(file2),
2378
+ ({ file: file2 }) => {
2379
+ return file2.endsWith(".json") ? import_parser2.ParserResult.fromJson(fs3.readFileSync(file2)) : ctx.project.parseSourceFile(file2);
2380
+ },
2399
2381
  (error) => import_logger3.logger.error("file:parse", error)
2400
2382
  )
2401
2383
  ),
@@ -2705,9 +2687,9 @@ async function debugFiles(ctx, options) {
2705
2687
  measure();
2706
2688
  if (!result)
2707
2689
  return;
2708
- const list = result.getAll().map((result2) => {
2690
+ const list = result.toArray().map((result2) => {
2709
2691
  const node = result2.box.getNode();
2710
- const range = getNodeRange(node);
2692
+ const range = result2.box.getRange();
2711
2693
  return {
2712
2694
  name: result2.name,
2713
2695
  type: result2.type,
@@ -2727,9 +2709,9 @@ async function debugFiles(ctx, options) {
2727
2709
  if (options.outdir) {
2728
2710
  filesWithCss.push(file);
2729
2711
  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, "__");
2712
+ const relative4 = path2.relative(ctx.config.cwd, parsedPath.dir);
2713
+ const astJsonPath = `${relative4}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2714
+ const cssPath = `${relative4}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2733
2715
  import_logger5.logger.info("cli", `Writing ${import_logger5.colors.bold(`${options.outdir}/${astJsonPath}`)}`);
2734
2716
  import_logger5.logger.info("cli", `Writing ${import_logger5.colors.bold(`${options.outdir}/${cssPath}`)}`);
2735
2717
  return Promise.all([
@@ -2797,7 +2779,7 @@ async function generate(config, configPath) {
2797
2779
  const ctx = ctxRef.current;
2798
2780
  await build(ctx);
2799
2781
  const {
2800
- runtime: { fs: fs3, path: path3 },
2782
+ runtime: { fs: fs3, path: path4 },
2801
2783
  dependencies,
2802
2784
  config: { cwd }
2803
2785
  } = ctx;
@@ -2812,7 +2794,7 @@ async function generate(config, configPath) {
2812
2794
  contentWatcher.on("all", async (event, file) => {
2813
2795
  import_logger7.logger.info(`file:${event}`, file);
2814
2796
  (0, import_ts_pattern.match)(event).with("unlink", () => {
2815
- ctx.project.removeSourceFile(path3.abs(cwd, file));
2797
+ ctx.project.removeSourceFile(path4.abs(cwd, file));
2816
2798
  ctx.chunks.rm(file);
2817
2799
  }).with("change", async () => {
2818
2800
  ctx.project.reloadSourceFile(file);
@@ -2859,7 +2841,8 @@ var import_look_it_up3 = require("look-it-up");
2859
2841
  var import_outdent2 = require("outdent");
2860
2842
  var import_path5 = require("path");
2861
2843
  var import_preferred_pm2 = __toESM(require("preferred-pm"));
2862
- async function setupConfig(cwd, { force }) {
2844
+ async function setupConfig(cwd, opts = {}) {
2845
+ const { force, outExtension } = opts;
2863
2846
  const configFile = findConfig();
2864
2847
  const pmResult = await (0, import_preferred_pm2.default)(cwd);
2865
2848
  const pm = pmResult?.name ?? "npm";
@@ -2876,7 +2859,9 @@ async function setupConfig(cwd, { force }) {
2876
2859
  export default defineConfig({
2877
2860
  // Whether to use css reset
2878
2861
  preflight: true,
2879
-
2862
+ ${outExtension ? `
2863
+ // The extension for the emitted JavaScript files
2864
+ outExtension: '${outExtension}',` : ""}
2880
2865
  // Where to look for your css declarations
2881
2866
  include: ["./src/**/*.{js,jsx,ts,tsx}", "./pages/**/*.{js,jsx,ts,tsx}"],
2882
2867
 
@@ -2902,6 +2887,34 @@ async function setupPostcss(cwd) {
2902
2887
  `;
2903
2888
  await (0, import_fs_extra3.writeFile)((0, import_path5.join)(cwd, "postcss.config.cjs"), content);
2904
2889
  }
2890
+
2891
+ // src/ship-files.ts
2892
+ init_cjs_shims();
2893
+ var import_logger9 = require("@pandacss/logger");
2894
+ var import_parser3 = require("@pandacss/parser");
2895
+ var import_promises3 = require("fs/promises");
2896
+ var path3 = __toESM(require("path"));
2897
+ async function shipFiles(ctx, outfile) {
2898
+ const files = ctx.getFiles();
2899
+ const extractResult = (0, import_parser3.createParserResult)();
2900
+ const filesWithCss = [];
2901
+ files.forEach(async (file) => {
2902
+ const result = ctx.project.parseSourceFile(file);
2903
+ if (!result || result.isEmpty())
2904
+ return;
2905
+ const css = ctx.getParserCss(result);
2906
+ if (!css)
2907
+ return;
2908
+ extractResult.merge(result);
2909
+ filesWithCss.push(path3.relative(ctx.config.cwd, file));
2910
+ });
2911
+ import_logger9.logger.info("cli", `Found ${import_logger9.colors.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2912
+ const minify = ctx.config.minify;
2913
+ import_logger9.logger.info("cli", `Writing ${minify ? "[min] " : " "}${import_logger9.colors.bold(outfile)}`);
2914
+ const output = JSON.stringify(extractResult.toJSON(), null, minify ? 0 : 2);
2915
+ await (0, import_promises3.writeFile)(outfile, output);
2916
+ import_logger9.logger.info("cli", "Done!");
2917
+ }
2905
2918
  // Annotate the CommonJS export names for ESM import in node:
2906
2919
  0 && (module.exports = {
2907
2920
  Builder,
@@ -2918,5 +2931,6 @@ async function setupPostcss(cwd) {
2918
2931
  setupConfig,
2919
2932
  setupGitIgnore,
2920
2933
  setupPostcss,
2934
+ shipFiles,
2921
2935
  writeAnalyzeJSON
2922
2936
  });
package/dist/index.mjs CHANGED
@@ -481,7 +481,6 @@ import { discardDuplicate as discardDuplicate2 } from "@pandacss/core";
481
481
  init_esm_shims();
482
482
  import { logger } from "@pandacss/logger";
483
483
  import { writeFile } from "fs/promises";
484
- import { Node } from "ts-morph";
485
484
 
486
485
  // src/classify.ts
487
486
  init_esm_shims();
@@ -745,23 +744,6 @@ var getMostUsedInMap = (map, pickCount) => {
745
744
  return Array.from(map.entries()).map(([key, list]) => [key, list.size]).sort((a, b) => b[1] - a[1]).slice(0, pickCount).map(([key, count]) => ({ key, count }));
746
745
  };
747
746
 
748
- // src/get-node-range.ts
749
- init_esm_shims();
750
- var getNodeRange = (node) => {
751
- const src = node.getSourceFile();
752
- const [startPosition, endPosition] = [node.getStart(), node.getEnd()];
753
- const startInfo = src.getLineAndColumnAtPos(startPosition);
754
- const endInfo = src.getLineAndColumnAtPos(endPosition);
755
- return {
756
- startPosition,
757
- startLineNumber: startInfo.line,
758
- startColumn: startInfo.column,
759
- endPosition,
760
- endLineNumber: endInfo.line,
761
- endColumn: endInfo.column
762
- };
763
- };
764
-
765
747
  // src/analyze-tokens.ts
766
748
  import { filesize } from "filesize";
767
749
 
@@ -781,7 +763,7 @@ function analyzeTokens(ctx, options = {}) {
781
763
  const parserResultByFilepath = /* @__PURE__ */ new Map();
782
764
  const extractTimeByFilepath = /* @__PURE__ */ new Map();
783
765
  const includedFiles = ctx.getFiles();
784
- includedFiles.map((file) => {
766
+ includedFiles.forEach((file) => {
785
767
  const start2 = performance.now();
786
768
  const result = ctx.project.parseSourceFile(file);
787
769
  const extractMs = performance.now() - start2;
@@ -791,7 +773,6 @@ function analyzeTokens(ctx, options = {}) {
791
773
  parserResultByFilepath.set(file, result);
792
774
  options.onResult?.(file, result);
793
775
  }
794
- return [file, result];
795
776
  });
796
777
  const totalMs = Array.from(extractTimeByFilepath.values()).reduce((a, b) => a + b, 0);
797
778
  logger.debug("analyze", `Analyzed ${includedFiles.length} files in ${totalMs.toFixed(2)}ms`);
@@ -834,14 +815,11 @@ var analyzeResultSerializer = (_key, value) => {
834
815
  if (value instanceof Map) {
835
816
  return Object.fromEntries(value);
836
817
  }
837
- if (Node.isNode(value)) {
838
- return { kind: value.getKindName(), range: getNodeRange(value) };
839
- }
840
818
  return value;
841
819
  };
842
820
  var writeAnalyzeJSON = (fileName, result, ctx) => {
843
821
  result.details.byInstanceId.forEach((item) => {
844
- item.box = { type: item.box.type, node: item.box.getNode(), stack: item.box.getStack() };
822
+ item.box = item.box.toJSON();
845
823
  });
846
824
  return writeFile(
847
825
  fileName,
@@ -883,18 +861,18 @@ import { Obj, pipe, tap } from "lil-fp";
883
861
  // src/chunk-engine.ts
884
862
  init_esm_shims();
885
863
  import { mergeCss } from "@pandacss/core";
886
- var getChunkEngine = ({ paths, config, runtime: { path: path3, fs: fs2 } }) => ({
887
- dir: path3.join(...paths.chunk),
864
+ var getChunkEngine = ({ paths, config, runtime: { path: path4, fs: fs2 } }) => ({
865
+ dir: path4.join(...paths.chunk),
888
866
  readFile(file) {
889
- const fileName = path3.join(...paths.chunk, this.format(file));
867
+ const fileName = path4.join(...paths.chunk, this.format(file));
890
868
  return fs2.existsSync(fileName) ? fs2.readFileSync(fileName) : "";
891
869
  },
892
870
  getFiles() {
893
871
  const files = fs2.existsSync(this.dir) ? fs2.readDirSync(this.dir) : [];
894
- return files.map((file) => fs2.readFileSync(path3.join(this.dir, file)));
872
+ return files.map((file) => fs2.readFileSync(path4.join(this.dir, file)));
895
873
  },
896
874
  format(file) {
897
- return path3.relative(config.cwd, file).replaceAll(path3.sep, "__").replace(path3.extname(file), ".css");
875
+ return path4.relative(config.cwd, file).replaceAll(path4.sep, "__").replace(path4.extname(file), ".css");
898
876
  },
899
877
  getArtifact(file, css) {
900
878
  const fileName = this.format(file);
@@ -905,7 +883,7 @@ var getChunkEngine = ({ paths, config, runtime: { path: path3, fs: fs2 } }) => (
905
883
  };
906
884
  },
907
885
  rm(file) {
908
- return fs2.rmFileSync(path3.join(...paths.chunk, this.format(file)));
886
+ return fs2.rmFileSync(path4.join(...paths.chunk, this.format(file)));
909
887
  },
910
888
  empty() {
911
889
  return fs2.rmDirSync(this.dir);
@@ -964,8 +942,8 @@ var nodeRuntime = {
964
942
  readDirSync: readdirSync,
965
943
  rmDirSync: emptyDirSync,
966
944
  rmFileSync: removeSync,
967
- ensureDirSync(path3) {
968
- return ensureDirSync(path3);
945
+ ensureDirSync(path4) {
946
+ return ensureDirSync(path4);
969
947
  },
970
948
  watch(options) {
971
949
  const { include, exclude, cwd, poll } = options;
@@ -996,18 +974,18 @@ process.on("uncaughtException", (reason) => {
996
974
 
997
975
  // src/output-engine.ts
998
976
  init_esm_shims();
999
- var getOutputEngine = ({ paths, runtime: { path: path3, fs: fs2 } }) => ({
977
+ var getOutputEngine = ({ paths, runtime: { path: path4, fs: fs2 } }) => ({
1000
978
  empty() {
1001
- fs2.rmDirSync(path3.join(...paths.root));
979
+ fs2.rmDirSync(path4.join(...paths.root));
1002
980
  },
1003
981
  async write(output) {
1004
982
  if (!output)
1005
983
  return;
1006
984
  const { dir = paths.root, files } = output;
1007
- fs2.ensureDirSync(path3.join(...dir));
985
+ fs2.ensureDirSync(path4.join(...dir));
1008
986
  return Promise.all(
1009
987
  files.map(async ({ file, code }) => {
1010
- const absPath = path3.join(...dir, file);
988
+ const absPath = path4.join(...dir, file);
1011
989
  if (code) {
1012
990
  return fs2.writeFile(absPath, code);
1013
991
  }
@@ -2356,6 +2334,7 @@ var createBox = (options) => boxen(options.content, {
2356
2334
  });
2357
2335
 
2358
2336
  // src/extract.ts
2337
+ import { ParserResult } from "@pandacss/parser";
2359
2338
  async function bundleChunks(ctx) {
2360
2339
  const files = ctx.chunks.getFiles();
2361
2340
  return ctx.output.write({
@@ -2364,8 +2343,8 @@ async function bundleChunks(ctx) {
2364
2343
  });
2365
2344
  }
2366
2345
  async function writeFileChunk(ctx, file) {
2367
- const { path: path3 } = ctx.runtime;
2368
- logger3.debug("chunk:write", `File: ${path3.relative(ctx.config.cwd, file)}`);
2346
+ const { path: path4 } = ctx.runtime;
2347
+ logger3.debug("chunk:write", `File: ${path4.relative(ctx.config.cwd, file)}`);
2369
2348
  const css = extractFile(ctx, file);
2370
2349
  if (!css)
2371
2350
  return;
@@ -2374,17 +2353,19 @@ async function writeFileChunk(ctx, file) {
2374
2353
  }
2375
2354
  function extractFile(ctx, file) {
2376
2355
  const {
2377
- runtime: { path: path3 },
2356
+ runtime: { path: path4, fs: fs2 },
2378
2357
  config: { cwd }
2379
2358
  } = ctx;
2380
2359
  return pipe2(
2381
- { file: path3.abs(cwd, file) },
2360
+ { file: path4.abs(cwd, file) },
2382
2361
  tap2(() => logger3.debug("file:extract", file)),
2383
2362
  Obj2.bind("measure", () => logger3.time.debug(`Extracted ${file}`)),
2384
2363
  Obj2.bind(
2385
2364
  "result",
2386
2365
  tryCatch(
2387
- ({ file: file2 }) => ctx.project.parseSourceFile(file2),
2366
+ ({ file: file2 }) => {
2367
+ return file2.endsWith(".json") ? ParserResult.fromJson(fs2.readFileSync(file2)) : ctx.project.parseSourceFile(file2);
2368
+ },
2388
2369
  (error) => logger3.error("file:parse", error)
2389
2370
  )
2390
2371
  ),
@@ -2694,9 +2675,9 @@ async function debugFiles(ctx, options) {
2694
2675
  measure();
2695
2676
  if (!result)
2696
2677
  return;
2697
- const list = result.getAll().map((result2) => {
2678
+ const list = result.toArray().map((result2) => {
2698
2679
  const node = result2.box.getNode();
2699
- const range = getNodeRange(node);
2680
+ const range = result2.box.getRange();
2700
2681
  return {
2701
2682
  name: result2.name,
2702
2683
  type: result2.type,
@@ -2716,9 +2697,9 @@ async function debugFiles(ctx, options) {
2716
2697
  if (options.outdir) {
2717
2698
  filesWithCss.push(file);
2718
2699
  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, "__");
2700
+ const relative4 = path2.relative(ctx.config.cwd, parsedPath.dir);
2701
+ const astJsonPath = `${relative4}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2702
+ const cssPath = `${relative4}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2722
2703
  logger5.info("cli", `Writing ${colors.bold(`${options.outdir}/${astJsonPath}`)}`);
2723
2704
  logger5.info("cli", `Writing ${colors.bold(`${options.outdir}/${cssPath}`)}`);
2724
2705
  return Promise.all([
@@ -2786,7 +2767,7 @@ async function generate(config, configPath) {
2786
2767
  const ctx = ctxRef.current;
2787
2768
  await build(ctx);
2788
2769
  const {
2789
- runtime: { fs: fs2, path: path3 },
2770
+ runtime: { fs: fs2, path: path4 },
2790
2771
  dependencies,
2791
2772
  config: { cwd }
2792
2773
  } = ctx;
@@ -2801,7 +2782,7 @@ async function generate(config, configPath) {
2801
2782
  contentWatcher.on("all", async (event, file) => {
2802
2783
  logger7.info(`file:${event}`, file);
2803
2784
  match(event).with("unlink", () => {
2804
- ctx.project.removeSourceFile(path3.abs(cwd, file));
2785
+ ctx.project.removeSourceFile(path4.abs(cwd, file));
2805
2786
  ctx.chunks.rm(file);
2806
2787
  }).with("change", async () => {
2807
2788
  ctx.project.reloadSourceFile(file);
@@ -2848,7 +2829,8 @@ import { lookItUpSync as lookItUpSync3 } from "look-it-up";
2848
2829
  import { outdent as outdent2 } from "outdent";
2849
2830
  import { join as join2 } from "path";
2850
2831
  import getPackageManager2 from "preferred-pm";
2851
- async function setupConfig(cwd, { force }) {
2832
+ async function setupConfig(cwd, opts = {}) {
2833
+ const { force, outExtension } = opts;
2852
2834
  const configFile = findConfig();
2853
2835
  const pmResult = await getPackageManager2(cwd);
2854
2836
  const pm = pmResult?.name ?? "npm";
@@ -2865,7 +2847,9 @@ async function setupConfig(cwd, { force }) {
2865
2847
  export default defineConfig({
2866
2848
  // Whether to use css reset
2867
2849
  preflight: true,
2868
-
2850
+ ${outExtension ? `
2851
+ // The extension for the emitted JavaScript files
2852
+ outExtension: '${outExtension}',` : ""}
2869
2853
  // Where to look for your css declarations
2870
2854
  include: ["./src/**/*.{js,jsx,ts,tsx}", "./pages/**/*.{js,jsx,ts,tsx}"],
2871
2855
 
@@ -2891,6 +2875,34 @@ async function setupPostcss(cwd) {
2891
2875
  `;
2892
2876
  await writeFile4(join2(cwd, "postcss.config.cjs"), content);
2893
2877
  }
2878
+
2879
+ // src/ship-files.ts
2880
+ init_esm_shims();
2881
+ import { colors as colors2, logger as logger9 } from "@pandacss/logger";
2882
+ import { createParserResult } from "@pandacss/parser";
2883
+ import { writeFile as writeFile5 } from "fs/promises";
2884
+ import * as path3 from "path";
2885
+ async function shipFiles(ctx, outfile) {
2886
+ const files = ctx.getFiles();
2887
+ const extractResult = createParserResult();
2888
+ const filesWithCss = [];
2889
+ files.forEach(async (file) => {
2890
+ const result = ctx.project.parseSourceFile(file);
2891
+ if (!result || result.isEmpty())
2892
+ return;
2893
+ const css = ctx.getParserCss(result);
2894
+ if (!css)
2895
+ return;
2896
+ extractResult.merge(result);
2897
+ filesWithCss.push(path3.relative(ctx.config.cwd, file));
2898
+ });
2899
+ logger9.info("cli", `Found ${colors2.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2900
+ const minify = ctx.config.minify;
2901
+ logger9.info("cli", `Writing ${minify ? "[min] " : " "}${colors2.bold(outfile)}`);
2902
+ const output = JSON.stringify(extractResult.toJSON(), null, minify ? 0 : 2);
2903
+ await writeFile5(outfile, output);
2904
+ logger9.info("cli", "Done!");
2905
+ }
2894
2906
  export {
2895
2907
  Builder,
2896
2908
  analyzeTokens,
@@ -2906,5 +2918,6 @@ export {
2906
2918
  setupConfig,
2907
2919
  setupGitIgnore,
2908
2920
  setupPostcss,
2921
+ shipFiles,
2909
2922
  writeAnalyzeJSON
2910
2923
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/node",
3
- "version": "0.0.0-dev-20230530090525",
3
+ "version": "0.0.0-dev-20230530140607",
4
4
  "description": "The core css panda library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -22,7 +22,6 @@
22
22
  "glob-parent": "^6.0.2",
23
23
  "hookable": "5.5.3",
24
24
  "is-glob": "^4.0.3",
25
- "javascript-stringify": "2.1.0",
26
25
  "lil-fp": "1.4.5",
27
26
  "lodash.merge": "4.6.2",
28
27
  "look-it-up": "2.1.0",
@@ -33,17 +32,17 @@
33
32
  "preferred-pm": "^3.0.3",
34
33
  "ts-morph": "18.0.0",
35
34
  "ts-pattern": "4.3.0",
36
- "@pandacss/config": "0.0.0-dev-20230530090525",
37
- "@pandacss/core": "0.0.0-dev-20230530090525",
38
- "@pandacss/error": "0.0.0-dev-20230530090525",
39
- "@pandacss/generator": "0.0.0-dev-20230530090525",
40
- "@pandacss/is-valid-prop": "0.0.0-dev-20230530090525",
41
- "@pandacss/logger": "0.0.0-dev-20230530090525",
42
- "@pandacss/parser": "0.0.0-dev-20230530090525",
43
- "@pandacss/extractor": "0.0.0-dev-20230530090525",
44
- "@pandacss/shared": "0.0.0-dev-20230530090525",
45
- "@pandacss/token-dictionary": "0.0.0-dev-20230530090525",
46
- "@pandacss/types": "0.0.0-dev-20230530090525"
35
+ "@pandacss/config": "0.0.0-dev-20230530140607",
36
+ "@pandacss/core": "0.0.0-dev-20230530140607",
37
+ "@pandacss/error": "0.0.0-dev-20230530140607",
38
+ "@pandacss/extractor": "0.0.0-dev-20230530140607",
39
+ "@pandacss/generator": "0.0.0-dev-20230530140607",
40
+ "@pandacss/is-valid-prop": "0.0.0-dev-20230530140607",
41
+ "@pandacss/logger": "0.0.0-dev-20230530140607",
42
+ "@pandacss/parser": "0.0.0-dev-20230530140607",
43
+ "@pandacss/shared": "0.0.0-dev-20230530140607",
44
+ "@pandacss/token-dictionary": "0.0.0-dev-20230530140607",
45
+ "@pandacss/types": "0.0.0-dev-20230530140607"
47
46
  },
48
47
  "devDependencies": {
49
48
  "@types/fs-extra": "11.0.1",
@@ -53,7 +52,7 @@
53
52
  "@types/pluralize": "0.0.29",
54
53
  "boxen": "^7.1.0",
55
54
  "gzip-size": "^7.0.0",
56
- "@pandacss/fixture": "0.0.0-dev-20230530090525"
55
+ "@pandacss/fixture": "0.0.0-dev-20230530140607"
57
56
  },
58
57
  "scripts": {
59
58
  "build": "tsup src/index.ts --format=cjs,esm --shims --dts",