@salty-css/core 0.1.0-alpha.31 → 0.1.0-alpha.33
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.
|
@@ -17,8 +17,9 @@ const module$1 = require("module");
|
|
|
17
17
|
const parseStyles = require("../parse-styles-lOMGe_c5.cjs");
|
|
18
18
|
const css_merge = require("../css/merge.cjs");
|
|
19
19
|
const parsers_index = require("../parsers/index.cjs");
|
|
20
|
-
const
|
|
20
|
+
const compiler_getFiles = require("./get-files.cjs");
|
|
21
21
|
const console = require("console");
|
|
22
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
22
23
|
function _interopNamespaceDefault(e) {
|
|
23
24
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
24
25
|
if (e) {
|
|
@@ -92,6 +93,20 @@ const resolveImport = (spec, sourceFile, destDir, options = {}) => {
|
|
|
92
93
|
copyAsset(absolute, destPath);
|
|
93
94
|
return { rule: buildRule(`../imports/${fileName}`, opts) };
|
|
94
95
|
};
|
|
96
|
+
const readPackageJsonModule = async (dirname) => {
|
|
97
|
+
const packageJsonContent = await compiler_getFiles.getPackageJson(dirname);
|
|
98
|
+
if (!packageJsonContent) return void 0;
|
|
99
|
+
return packageJsonContent.type;
|
|
100
|
+
};
|
|
101
|
+
let cachedModuleType;
|
|
102
|
+
const detectCurrentModuleType = async (dirname) => {
|
|
103
|
+
if (cachedModuleType) return cachedModuleType;
|
|
104
|
+
const packageJsonModule = await readPackageJsonModule(dirname);
|
|
105
|
+
if (packageJsonModule === "module") cachedModuleType = "esm";
|
|
106
|
+
else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
|
|
107
|
+
else if ((typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("compiler/salty-compiler.cjs", document.baseURI).href).endsWith(".cjs")) cachedModuleType = "cjs";
|
|
108
|
+
return cachedModuleType || "esm";
|
|
109
|
+
};
|
|
95
110
|
function dotCase(str) {
|
|
96
111
|
if (!str) return "";
|
|
97
112
|
if (typeof str !== "string") return dotCase(String(str));
|
|
@@ -207,7 +222,7 @@ class SaltyCompiler {
|
|
|
207
222
|
const destDir = await this.getDestDir();
|
|
208
223
|
const coreConfigPath = path.join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
|
|
209
224
|
const coreConfigDest = path.join(destDir, "salty.config.js");
|
|
210
|
-
const moduleType
|
|
225
|
+
const moduleType = await detectCurrentModuleType(this.projectRootDir);
|
|
211
226
|
const externalModules = this.getExternalModules(coreConfigPath);
|
|
212
227
|
await esbuild__namespace.build({
|
|
213
228
|
entryPoints: [coreConfigPath],
|
|
@@ -215,7 +230,7 @@ class SaltyCompiler {
|
|
|
215
230
|
treeShaking: true,
|
|
216
231
|
bundle: true,
|
|
217
232
|
outfile: coreConfigDest,
|
|
218
|
-
format: moduleType
|
|
233
|
+
format: moduleType,
|
|
219
234
|
external: externalModules
|
|
220
235
|
});
|
|
221
236
|
const { config } = await this.importFile(coreConfigDest);
|
|
@@ -649,7 +664,7 @@ ${css}
|
|
|
649
664
|
const rcProject = await this.getRCProjectConfig(this.projectRootDir);
|
|
650
665
|
const coreConfigPath = path.join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
|
|
651
666
|
const externalModules = this.getExternalModules(coreConfigPath);
|
|
652
|
-
const moduleType
|
|
667
|
+
const moduleType = await detectCurrentModuleType(this.projectRootDir);
|
|
653
668
|
await esbuild__namespace.build({
|
|
654
669
|
stdin: {
|
|
655
670
|
contents: currentFile,
|
|
@@ -661,7 +676,7 @@ ${css}
|
|
|
661
676
|
treeShaking: true,
|
|
662
677
|
bundle: true,
|
|
663
678
|
outfile: outputFilePath,
|
|
664
|
-
format: moduleType
|
|
679
|
+
format: moduleType,
|
|
665
680
|
target: ["node20"],
|
|
666
681
|
keepNames: true,
|
|
667
682
|
external: externalModules,
|
|
@@ -15,7 +15,7 @@ import { createRequire } from "module";
|
|
|
15
15
|
import { p as parseAndJoinStyles, c as parseVariableTokens } from "../parse-styles-BBJ3PWyV.js";
|
|
16
16
|
import { mergeObjects, mergeFactories } from "../css/merge.js";
|
|
17
17
|
import { parseTemplates, getTemplateTypes, getTemplateVariantMaps } from "../parsers/index.js";
|
|
18
|
-
import {
|
|
18
|
+
import { getPackageJson } from "./get-files.js";
|
|
19
19
|
import console from "console";
|
|
20
20
|
const logger = createLogger({
|
|
21
21
|
level: "debug",
|
|
@@ -73,6 +73,20 @@ const resolveImport = (spec, sourceFile, destDir, options = {}) => {
|
|
|
73
73
|
copyAsset(absolute, destPath);
|
|
74
74
|
return { rule: buildRule(`../imports/${fileName}`, opts) };
|
|
75
75
|
};
|
|
76
|
+
const readPackageJsonModule = async (dirname2) => {
|
|
77
|
+
const packageJsonContent = await getPackageJson(dirname2);
|
|
78
|
+
if (!packageJsonContent) return void 0;
|
|
79
|
+
return packageJsonContent.type;
|
|
80
|
+
};
|
|
81
|
+
let cachedModuleType;
|
|
82
|
+
const detectCurrentModuleType = async (dirname2) => {
|
|
83
|
+
if (cachedModuleType) return cachedModuleType;
|
|
84
|
+
const packageJsonModule = await readPackageJsonModule(dirname2);
|
|
85
|
+
if (packageJsonModule === "module") cachedModuleType = "esm";
|
|
86
|
+
else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
|
|
87
|
+
else if (import.meta.url.endsWith(".cjs")) cachedModuleType = "cjs";
|
|
88
|
+
return cachedModuleType || "esm";
|
|
89
|
+
};
|
|
76
90
|
function dotCase(str) {
|
|
77
91
|
if (!str) return "";
|
|
78
92
|
if (typeof str !== "string") return dotCase(String(str));
|