@knighted/css 1.0.8 → 1.0.9

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.
@@ -11,11 +11,11 @@ const promises_1 = __importDefault(require("node:fs/promises"));
11
11
  const node_path_1 = __importDefault(require("node:path"));
12
12
  const node_module_1 = require("node:module");
13
13
  const node_url_1 = require("node:url");
14
- const es_module_lexer_1 = require("es-module-lexer");
15
14
  const node_module_type_1 = require("node-module-type");
16
15
  const get_tsconfig_1 = require("get-tsconfig");
17
16
  const tsconfig_paths_1 = require("tsconfig-paths");
18
17
  const css_js_1 = require("./css.cjs");
18
+ const lexer_js_1 = require("./lexer.cjs");
19
19
  const stableSelectorsLiteral_js_1 = require("./stableSelectorsLiteral.cjs");
20
20
  const stableNamespace_js_1 = require("./stableNamespace.cjs");
21
21
  let activeCssWithMeta = css_js_1.cssWithMeta;
@@ -70,7 +70,6 @@ async function generateTypes(options = {}) {
70
70
  const include = normalizeIncludeOptions(options.include, rootDir);
71
71
  const cacheDir = node_path_1.default.resolve(options.outDir ?? node_path_1.default.join(rootDir, '.knighted-css'));
72
72
  const tsconfig = loadTsconfigResolutionContext(rootDir);
73
- await es_module_lexer_1.init;
74
73
  await promises_1.default.mkdir(cacheDir, { recursive: true });
75
74
  const internalOptions = {
76
75
  rootDir,
@@ -211,13 +210,17 @@ async function findSpecifierImports(filePath) {
211
210
  return [];
212
211
  }
213
212
  const matches = [];
214
- const [imports] = (0, es_module_lexer_1.parse)(source, filePath);
215
- for (const record of imports) {
216
- const specifier = record.n ?? source.slice(record.s, record.e);
217
- if (specifier && specifier.includes(SELECTOR_REFERENCE)) {
218
- matches.push({ specifier, importer: filePath });
213
+ try {
214
+ const { imports } = await (0, lexer_js_1.analyzeModule)(source, filePath);
215
+ for (const specifier of imports) {
216
+ if (specifier.includes(SELECTOR_REFERENCE)) {
217
+ matches.push({ specifier, importer: filePath });
218
+ }
219
219
  }
220
220
  }
221
+ catch {
222
+ // ignore and fall back to regex below
223
+ }
221
224
  const requireRegex = /require\((['"])([^'"`]+?\.knighted-css[^'"`]*)\1\)/g;
222
225
  let reqMatch;
223
226
  while ((reqMatch = requireRegex.exec(source)) !== null) {