@absolutejs/absolute 0.19.0-beta.692 → 0.19.0-beta.693

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.
@@ -1,11 +1,13 @@
1
1
  import type { BunPlugin } from 'bun';
2
+ import type { StylePreprocessorConfig } from '../../types/build';
2
3
  export declare const isPreprocessableStylePath: (filePath: string) => boolean;
3
4
  export declare const isStyleModulePath: (filePath: string) => boolean;
4
5
  export declare const isStylePath: (filePath: string) => boolean;
5
6
  export declare const getStyleBaseName: (filePath: string) => string;
6
- export declare const compileStyleSource: (filePath: string, source?: string, languageHint?: string) => Promise<string>;
7
+ export declare const compileStyleSource: (filePath: string, source?: string, languageHint?: string, config?: StylePreprocessorConfig) => Promise<string>;
8
+ export declare const createStylePreprocessorPlugin: (config?: StylePreprocessorConfig) => BunPlugin;
7
9
  export declare const stylePreprocessorPlugin: BunPlugin;
8
- export declare const createSvelteStylePreprocessor: () => {
10
+ export declare const createSvelteStylePreprocessor: (config?: StylePreprocessorConfig) => {
9
11
  style: ({ attributes, content, filename }: {
10
12
  attributes: Record<string, string | boolean>;
11
13
  content: string;
@@ -14,6 +16,6 @@ export declare const createSvelteStylePreprocessor: () => {
14
16
  code: string;
15
17
  } | undefined>;
16
18
  };
17
- export declare const compileStyleFileIfNeeded: (filePath: string) => Promise<string>;
18
- export declare const compileStyleFileIfNeededSync: (filePath: string) => string;
19
+ export declare const compileStyleFileIfNeeded: (filePath: string, config?: StylePreprocessorConfig) => Promise<string>;
20
+ export declare const compileStyleFileIfNeededSync: (filePath: string, config?: StylePreprocessorConfig) => string;
19
21
  export declare const getCssOutputExtension: (filePath: string) => string;
@@ -1,6 +1,6 @@
1
1
  import type { ConventionsMap } from '../../types/conventions';
2
2
  import type { BuildConfig } from '../../types/build';
3
- export declare const build: ({ buildDirectory, assetsDirectory, publicDirectory, islands, reactDirectory, htmlDirectory, htmxDirectory, angularDirectory, svelteDirectory, vueDirectory, stylesConfig, tailwind, options, incrementalFiles, mode }: BuildConfig) => Promise<{
3
+ export declare const build: ({ buildDirectory, assetsDirectory, publicDirectory, islands, reactDirectory, htmlDirectory, htmxDirectory, angularDirectory, svelteDirectory, vueDirectory, stylesConfig, stylePreprocessors, tailwind, options, incrementalFiles, mode }: BuildConfig) => Promise<{
4
4
  conventions?: undefined;
5
5
  manifest?: undefined;
6
6
  } | {
@@ -1,3 +1,4 @@
1
+ import type { StylePreprocessorConfig } from '../../types/build';
1
2
  type ModuleServerConfig = {
2
3
  projectRoot: string;
3
4
  vendorPaths: Record<string, string>;
@@ -7,6 +8,7 @@ type ModuleServerConfig = {
7
8
  svelte?: string;
8
9
  vue?: string;
9
10
  };
11
+ stylePreprocessors?: StylePreprocessorConfig;
10
12
  };
11
13
  export declare const warmCompilers: (frameworks: {
12
14
  svelte?: boolean;
@@ -361,7 +361,7 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
361
361
  // src/build/stylePreprocessor.ts
362
362
  import { readFile } from "fs/promises";
363
363
  import { createRequire } from "module";
364
- import { dirname, extname, join as join2 } from "path";
364
+ import { dirname, extname, join as join2, resolve as resolve2 } from "path";
365
365
  var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, requireOptionalPeer, requireFromCwd, isPreprocessableStylePath = (filePath) => STYLE_EXTENSION_PATTERN.test(filePath), isStyleModulePath = (filePath) => STYLE_MODULE_EXTENSION_PATTERN.test(filePath), isStylePath = (filePath) => /\.(css|s[ac]ss|less)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
366
366
  const normalized = filePathOrLanguage.toLowerCase();
367
367
  if (normalized === "scss" || normalized.endsWith(".scss"))
@@ -371,18 +371,29 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
371
371
  if (normalized === "less" || normalized.endsWith(".less"))
372
372
  return "less";
373
373
  return null;
374
- }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), compileStyleSource = async (filePath, source, languageHint) => {
374
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
375
+ dirname(filePath),
376
+ process.cwd(),
377
+ ...paths.map((path) => resolve2(process.cwd(), path))
378
+ ], getSassOptions = (config, language) => ({
379
+ ...config?.sass ?? {},
380
+ ...language === "scss" ? config?.scss ?? {} : {}
381
+ }), getLessOptions = (config) => config?.less ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
382
+ ${contents}` : contents, compileStyleSource = async (filePath, source, languageHint, config) => {
375
383
  const language = getStyleLanguage(languageHint ?? filePath);
376
- const contents = source ?? await readFile(filePath, "utf-8");
384
+ const rawContents = source ?? await readFile(filePath, "utf-8");
377
385
  if (language === "scss" || language === "sass") {
386
+ const options = getSassOptions(config, language);
387
+ const packageName = options.implementation ?? "sass";
378
388
  let sass;
379
389
  try {
380
- sass = await importOptionalPeer("sass");
390
+ sass = await importOptionalPeer(packageName);
381
391
  } catch {
382
- throw missingDependencyError("sass", filePath);
392
+ throw missingDependencyError(packageName, filePath);
383
393
  }
394
+ const contents = withAdditionalData(rawContents, options.additionalData);
384
395
  const result = sass.compileString(contents, {
385
- loadPaths: [dirname(filePath), process.cwd()],
396
+ loadPaths: normalizeLoadPaths(filePath, options.loadPaths),
386
397
  style: "expanded",
387
398
  syntax: language === "sass" ? "indented" : "scss",
388
399
  url: new URL(`file://${filePath}`)
@@ -390,6 +401,7 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
390
401
  return result.css;
391
402
  }
392
403
  if (language === "less") {
404
+ const options = getLessOptions(config);
393
405
  let lessModule;
394
406
  try {
395
407
  lessModule = await importOptionalPeer("less");
@@ -400,14 +412,49 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
400
412
  const render = less?.render;
401
413
  if (!render)
402
414
  throw missingDependencyError("less", filePath);
415
+ const contents = withAdditionalData(rawContents, options.additionalData);
403
416
  const result = await render(contents, {
417
+ ...options.options ?? {},
404
418
  filename: filePath,
405
- paths: [dirname(filePath), process.cwd()]
419
+ paths: normalizeLoadPaths(filePath, options.paths)
406
420
  });
407
421
  return result.css;
408
422
  }
409
- return contents;
410
- }, stylePreprocessorPlugin, createSvelteStylePreprocessor = () => ({
423
+ return rawContents;
424
+ }, createStylePreprocessorPlugin = (config) => ({
425
+ name: "absolute-style-preprocessor",
426
+ setup(build) {
427
+ const cssModuleSources = new Map;
428
+ build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
429
+ namespace: "absolute-style-module",
430
+ path: path.slice("absolute-style-module:".length)
431
+ }));
432
+ build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
433
+ const sourcePath = cssModuleSources.get(path);
434
+ if (!sourcePath) {
435
+ throw new Error(`Unable to resolve CSS module source for ${path}`);
436
+ }
437
+ return {
438
+ contents: await compileStyleSource(sourcePath, undefined, undefined, config),
439
+ loader: "css"
440
+ };
441
+ });
442
+ build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
443
+ if (isStyleModulePath(path)) {
444
+ const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
445
+ cssModuleSources.set(cssModulePath, path);
446
+ return {
447
+ contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
448
+ loader: "js"
449
+ };
450
+ }
451
+ return {
452
+ contents: await compileStyleSource(path, undefined, undefined, config),
453
+ loader: "css"
454
+ };
455
+ });
456
+ }
457
+ }), stylePreprocessorPlugin, createSvelteStylePreprocessor = (config) => ({
411
458
  style: async ({
412
459
  attributes,
413
460
  content,
@@ -418,14 +465,14 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
418
465
  return;
419
466
  const path = filename ?? `style.${language}`;
420
467
  return {
421
- code: await compileStyleSource(path, content, language)
468
+ code: await compileStyleSource(path, content, language, config)
422
469
  };
423
470
  }
424
- }), compileStyleFileIfNeeded = async (filePath) => {
471
+ }), compileStyleFileIfNeeded = async (filePath, config) => {
425
472
  if (!isPreprocessableStylePath(filePath)) {
426
473
  return readFile(filePath, "utf-8");
427
474
  }
428
- return compileStyleSource(filePath);
475
+ return compileStyleSource(filePath, undefined, undefined, config);
429
476
  };
430
477
  var init_stylePreprocessor = __esm(() => {
431
478
  STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
@@ -434,45 +481,12 @@ var init_stylePreprocessor = __esm(() => {
434
481
  importOptionalPeer = new Function("specifier", "return import(specifier)");
435
482
  requireOptionalPeer = new Function("specifier", "return require(specifier)");
436
483
  requireFromCwd = createRequire(join2(process.cwd(), "package.json"));
437
- stylePreprocessorPlugin = {
438
- name: "absolute-style-preprocessor",
439
- setup(build) {
440
- const cssModuleSources = new Map;
441
- build.onResolve({ filter: /^absolute-style-module:/ }, ({ path }) => ({
442
- namespace: "absolute-style-module",
443
- path: path.slice("absolute-style-module:".length)
444
- }));
445
- build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
446
- const sourcePath = cssModuleSources.get(path);
447
- if (!sourcePath) {
448
- throw new Error(`Unable to resolve CSS module source for ${path}`);
449
- }
450
- return {
451
- contents: await compileStyleSource(sourcePath),
452
- loader: "css"
453
- };
454
- });
455
- build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
456
- if (isStyleModulePath(path)) {
457
- const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
458
- cssModuleSources.set(cssModulePath, path);
459
- return {
460
- contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
461
- loader: "js"
462
- };
463
- }
464
- return {
465
- contents: await compileStyleSource(path),
466
- loader: "css"
467
- };
468
- });
469
- }
470
- };
484
+ stylePreprocessorPlugin = createStylePreprocessorPlugin();
471
485
  });
472
486
 
473
487
  // src/core/svelteServerModule.ts
474
488
  import { mkdir, readdir } from "fs/promises";
475
- import { basename, dirname as dirname2, extname as extname2, join as join3, relative, resolve as resolve2 } from "path";
489
+ import { basename, dirname as dirname2, extname as extname2, join as join3, relative, resolve as resolve3 } from "path";
476
490
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
477
491
  const importPath = relative(dirname2(from), target).replace(/\\/g, "/");
478
492
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
@@ -520,7 +534,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
520
534
  if (!spec.startsWith(".")) {
521
535
  return null;
522
536
  }
523
- const basePath = resolve2(dirname2(from), spec);
537
+ const basePath = resolve3(dirname2(from), spec);
524
538
  const candidates = [
525
539
  basePath,
526
540
  `${basePath}.ts`,
@@ -552,7 +566,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
552
566
  if (!spec.startsWith(".")) {
553
567
  return null;
554
568
  }
555
- const explicitPath = resolve2(dirname2(from), spec);
569
+ const explicitPath = resolve3(dirname2(from), spec);
556
570
  if (extname2(explicitPath) === ".svelte") {
557
571
  return explicitPath;
558
572
  }
@@ -2283,7 +2297,7 @@ var init_pageHandler = __esm(() => {
2283
2297
 
2284
2298
  // src/angular/injectorPatch.ts
2285
2299
  import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
2286
- import { dirname as dirname3, join as join4, resolve as resolve3 } from "path";
2300
+ import { dirname as dirname3, join as join4, resolve as resolve4 } from "path";
2287
2301
  var applyInjectorPatch = (chunkPath, content) => {
2288
2302
  if (content.includes('Symbol.for("angular.currentInjector")')) {
2289
2303
  return;
@@ -2319,7 +2333,7 @@ var applyInjectorPatch = (chunkPath, content) => {
2319
2333
  }
2320
2334
  writeFileSync(chunkPath, patched, "utf-8");
2321
2335
  }, resolveAngularCoreDir = () => {
2322
- const fromProject = resolve3(process.cwd(), "node_modules/@angular/core");
2336
+ const fromProject = resolve4(process.cwd(), "node_modules/@angular/core");
2323
2337
  if (existsSync2(join4(fromProject, "package.json"))) {
2324
2338
  return fromProject;
2325
2339
  }
@@ -2338,9 +2352,9 @@ var init_injectorPatch = __esm(() => {
2338
2352
 
2339
2353
  // src/angular/resolveAngularPackage.ts
2340
2354
  import { existsSync as existsSync3 } from "fs";
2341
- import { resolve as resolve4 } from "path";
2355
+ import { resolve as resolve5 } from "path";
2342
2356
  var resolveAngularPackage = (specifier) => {
2343
- const fromProject = resolve4(process.cwd(), "node_modules", specifier);
2357
+ const fromProject = resolve5(process.cwd(), "node_modules", specifier);
2344
2358
  if (existsSync3(fromProject)) {
2345
2359
  return fromProject;
2346
2360
  }
@@ -3160,5 +3174,5 @@ export {
3160
3174
  createTypedIsland
3161
3175
  };
3162
3176
 
3163
- //# debugId=FEADEE763F16AA9D64756E2164756E21
3177
+ //# debugId=D77E1858501D2AE764756E2164756E21
3164
3178
  //# sourceMappingURL=index.js.map