@nooeh/cli 0.2.5 → 0.2.7

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/add.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { mkdir, readFile, writeFile } from "node:fs/promises";
2
- import { dirname, isAbsolute, join, relative, resolve } from "node:path";
2
+ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
3
  import { createInterface } from "node:readline/promises";
4
4
  import { defaultConfig, hasConfig, readConfig, resolveConfigAlias } from "./config.js";
5
5
  import { installDependencies } from "./dependencies.js";
@@ -49,8 +49,11 @@ function resolveTargetPath(uiDirectory, filePath) {
49
49
  }
50
50
  return targetPath;
51
51
  }
52
- function replaceTokenImport(source, stylesAlias) {
53
- return source.replaceAll("@nooeh/tokens/semantic.stylex", `${stylesAlias}/semantic.stylex`);
52
+ function replaceTokenImport(source, targetPath, stylesDirectory) {
53
+ const tokenPath = join(stylesDirectory, "semantic.stylex");
54
+ const importPath = relative(dirname(targetPath), tokenPath).split(sep).join("/");
55
+ const relativeImportPath = importPath.startsWith(".") ? importPath : `./${importPath}`;
56
+ return source.replaceAll("@nooeh/tokens/semantic.stylex", relativeImportPath);
54
57
  }
55
58
  export async function add(projectDirectory, componentName, options = {}) {
56
59
  if (!componentName)
@@ -65,6 +68,7 @@ export async function add(projectDirectory, componentName, options = {}) {
65
68
  const config = options["dry-run"] && shouldInitialize ? defaultConfig : await readConfig(projectDirectory);
66
69
  const resolved = await resolveComponent(componentName);
67
70
  const uiDirectory = await resolveConfigAlias(projectDirectory, config.aliases.ui, "aliases.ui");
71
+ const stylesDirectory = await resolveConfigAlias(projectDirectory, config.aliases.styles, "aliases.styles");
68
72
  let isOverwriteConfirmed = false;
69
73
  async function confirmOverwrite() {
70
74
  if (isOverwriteConfirmed)
@@ -78,7 +82,7 @@ export async function add(projectDirectory, componentName, options = {}) {
78
82
  console.log(`Will add: ${targetPath}`);
79
83
  continue;
80
84
  }
81
- await writeSource(replaceTokenImport(file.content, config.aliases.styles), targetPath, confirmOverwrite);
85
+ await writeSource(replaceTokenImport(file.content, targetPath, stylesDirectory), targetPath, confirmOverwrite);
82
86
  }
83
87
  const shouldInstallDependencies = resolved.externalDependencies.length > 0 &&
84
88
  !options.skipDependencyInstall &&
package/dist/doctor.js CHANGED
@@ -81,12 +81,7 @@ export async function doctor(projectDirectory) {
81
81
  name: "UI path",
82
82
  status: "pass",
83
83
  });
84
- const tokenFiles = [
85
- "color-palette.stylex.ts",
86
- "semantic.stylex.ts",
87
- "themes.stylex.ts",
88
- "theme-provider.tsx",
89
- ];
84
+ const tokenFiles = ["color-palette.stylex.ts", "semantic.stylex.ts", "themes.stylex.ts"];
90
85
  const hasTokenFiles = await Promise.all(tokenFiles.map(async (fileName) => {
91
86
  try {
92
87
  await access(resolve(tokenDirectory, fileName));
package/dist/init.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { access, mkdir, readFile, writeFile } from "node:fs/promises";
2
- import { join, relative, sep } from "node:path";
2
+ import { join, relative } from "node:path";
3
3
  import { createInterface } from "node:readline/promises";
4
4
  import { configFileName, defaultConfig, hasConfig, resolveConfigAlias, writeConfig, } from "./config.js";
5
5
  import { installDependencies } from "./dependencies.js";
@@ -33,40 +33,34 @@ async function readViteConfig(projectDirectory) {
33
33
  }
34
34
  throw new Error("Could not find a Vite config file.");
35
35
  }
36
- function getStylexPlugin(stylesAlias, tokenDirectory, projectDirectory) {
37
- const tokenPath = relative(projectDirectory, tokenDirectory).split(sep).join("/");
38
- const aliasPattern = `${stylesAlias}/*`;
39
- const aliasTarget = `/ROOT/${tokenPath}/*`;
40
- return `stylex.vite({
41
- aliases: { ${JSON.stringify(aliasPattern)}: [${JSON.stringify(aliasTarget)}] },
42
- unstable_moduleResolution: {
43
- type: "commonJS",
44
- rootDir: new URL(".", import.meta.url).pathname,
45
- },
46
- })`;
47
- }
48
- function configureVite(source, stylesAlias, tokenDirectory, projectDirectory) {
36
+ function configureVite(source) {
49
37
  const importLine = 'import stylex from "@stylexjs/unplugin";';
50
38
  const pluginPattern = /plugins:\s*\[([^\]]*)\]/s;
51
- const configPattern = /defineConfig\(\{\s*/;
52
- const stylexPlugin = getStylexPlugin(stylesAlias, tokenDirectory, projectDirectory);
39
+ const stylexPlugin = 'stylex.vite({ unstable_moduleResolution: { type: "commonJS" } })';
53
40
  const legacyStylexPluginPattern = /stylex\.vite\(\{\s*useCSSLayers:\s*true\s*\}\)/;
54
41
  const emptyStylexPluginPattern = /stylex\.vite\(\)/;
42
+ const moduleResolutionPluginPattern = /stylex\.vite\(\{\s*unstable_moduleResolution:\s*\{\s*type:\s*["']commonJS["']\s*\},?\s*\}\)/s;
43
+ const nooehStylexPluginPattern = /stylex\.vite\(\{\s*(?:\/\/[^\n]*\s*)?(?:useCSSLayers:\s*true,?\s*)?aliases:\s*\{[^}]*\},\s*unstable_moduleResolution:\s*\{\s*type:\s*["']commonJS["'],\s*rootDir:\s*new URL\(["']\.["'],\s*import\.meta\.url\)\.pathname,?\s*\},\s*\}\)/s;
55
44
  if (!source.includes("stylex.vite(") && !pluginPattern.test(source)) {
56
45
  throw new Error("Could not safely update the Vite plugins array. Add stylex.vite() manually.");
57
46
  }
58
- let withStylex = source;
47
+ if (nooehStylexPluginPattern.test(source)) {
48
+ return source.replace(nooehStylexPluginPattern, stylexPlugin);
49
+ }
50
+ if (moduleResolutionPluginPattern.test(source))
51
+ return source;
59
52
  if (source.includes("unstable_moduleResolution")) {
60
- withStylex = source.replace(/\s*useCSSLayers:\s*true,?/, "");
53
+ throw new Error("Could not safely simplify the existing StyleX plugin. Remove Nooeh's aliases and unstable_moduleResolution manually, then use stylex.vite().");
61
54
  }
62
- else if (legacyStylexPluginPattern.test(source)) {
55
+ let withStylex = source;
56
+ if (legacyStylexPluginPattern.test(source)) {
63
57
  withStylex = source.replace(legacyStylexPluginPattern, stylexPlugin);
64
58
  }
65
59
  else if (emptyStylexPluginPattern.test(source)) {
66
60
  withStylex = source.replace(emptyStylexPluginPattern, stylexPlugin);
67
61
  }
68
62
  else if (source.includes("stylex.vite(")) {
69
- throw new Error("Could not safely update the existing StyleX plugin. Add Nooeh's aliases and unstable_moduleResolution manually.");
63
+ throw new Error("Could not safely update the existing StyleX plugin. Configure stylex.vite() manually.");
70
64
  }
71
65
  else {
72
66
  withStylex = (source.includes(importLine) ? source : `${importLine}\n${source}`).replace(pluginPattern, (_, plugins) => {
@@ -74,16 +68,11 @@ function configureVite(source, stylesAlias, tokenDirectory, projectDirectory) {
74
68
  return `plugins: [${prefix}]`;
75
69
  });
76
70
  }
77
- if (withStylex.includes("alias:"))
78
- return withStylex;
79
- if (!configPattern.test(withStylex)) {
80
- throw new Error('Could not safely add the "@" Vite alias. Add resolve.alias["@"] manually.');
81
- }
82
- return withStylex.replace(configPattern, 'defineConfig({\n resolve: { alias: { "@": new URL("./src", import.meta.url).pathname } },\n ');
71
+ return withStylex;
83
72
  }
84
- async function writeViteFiles(projectDirectory, tokenDirectory, stylesAlias, refreshLegacyTokens) {
73
+ async function writeViteFiles(projectDirectory, tokenDirectory, refreshLegacyTokens) {
85
74
  const { path: configPath, source: configSource } = await readViteConfig(projectDirectory);
86
- const configuredVite = configureVite(configSource, stylesAlias, tokenDirectory, projectDirectory);
75
+ const configuredVite = configureVite(configSource);
87
76
  await writeNooehFiles(projectDirectory, tokenDirectory, refreshLegacyTokens);
88
77
  await writeFile(configPath, configuredVite, "utf8");
89
78
  console.log(`Configured Vite and created ${relative(projectDirectory, tokenDirectory)}.`);
@@ -94,18 +83,15 @@ async function writeNooehFiles(projectDirectory, tokenDirectory, refreshLegacyTo
94
83
  await writeTokenFile(join(tokenDirectory, file.name), file.content, refreshLegacyTokens, file.name);
95
84
  }
96
85
  }
97
- function isLegacyNooehSource(fileName, source) {
98
- if (fileName === "semantic.stylex.ts") {
99
- return source.includes('bgCanvas: "initial"') && source.includes('overlay: "initial"');
100
- }
101
- return (fileName === "theme-provider.tsx" &&
102
- source.includes("const styles = stylex.create({") &&
103
- source.includes("data-theme={resolvedTheme}"));
86
+ function isLegacySemanticSource(fileName, source) {
87
+ return (fileName === "semantic.stylex.ts" &&
88
+ source.includes('bgCanvas: "initial"') &&
89
+ source.includes('overlay: "initial"'));
104
90
  }
105
91
  async function writeTokenFile(path, source, shouldRefreshLegacySources, fileName) {
106
92
  try {
107
93
  const currentSource = await readFile(path, "utf8");
108
- if (shouldRefreshLegacySources && isLegacyNooehSource(fileName, currentSource)) {
94
+ if (shouldRefreshLegacySources && isLegacySemanticSource(fileName, currentSource)) {
109
95
  await writeFile(path, source, "utf8");
110
96
  }
111
97
  }
@@ -143,7 +129,7 @@ export async function init(projectDirectory, options) {
143
129
  }
144
130
  }
145
131
  if (options.framework === "vite") {
146
- await writeViteFiles(projectDirectory, tokenDirectory, stylesAlias, Boolean(options.force));
132
+ await writeViteFiles(projectDirectory, tokenDirectory, Boolean(options.force));
147
133
  }
148
134
  else {
149
135
  await writeNooehFiles(projectDirectory, tokenDirectory, Boolean(options.force));
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@nooeh/cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "private": false,
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/nooeh/ui.git"
8
+ },
5
9
  "bin": {
6
10
  "nooeh": "./dist/cli.js"
7
11
  },