@pandacss/config 0.0.0-dev-20221121152823
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/LICENSE.md +21 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +153 -0
- package/dist/index.mjs +128 -0
- package/package.json +30 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Segun Adebayo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UserConfig } from '@pandacss/types';
|
|
2
|
+
|
|
3
|
+
declare type ConfigFileOptions = {
|
|
4
|
+
cwd: string;
|
|
5
|
+
file?: string;
|
|
6
|
+
};
|
|
7
|
+
declare function loadConfigFile(options: ConfigFileOptions): Promise<{
|
|
8
|
+
path: string;
|
|
9
|
+
config: UserConfig;
|
|
10
|
+
dependencies: string[];
|
|
11
|
+
}>;
|
|
12
|
+
declare type LoadConfigResult = {
|
|
13
|
+
path: string;
|
|
14
|
+
config: UserConfig;
|
|
15
|
+
dependencies: string[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { LoadConfigResult, loadConfigFile };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
loadConfigFile: () => loadConfigFile
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// src/load-config.ts
|
|
34
|
+
var import_error = require("@pandacss/error");
|
|
35
|
+
var import_logger2 = require("@pandacss/logger");
|
|
36
|
+
var import_merge_anything = require("merge-anything");
|
|
37
|
+
|
|
38
|
+
// src/bundle-require.ts
|
|
39
|
+
var import_logger = require("@pandacss/logger");
|
|
40
|
+
var import_fs2 = require("fs");
|
|
41
|
+
var import_path2 = require("path");
|
|
42
|
+
|
|
43
|
+
// src/bundle-config.ts
|
|
44
|
+
var import_esbuild = require("esbuild");
|
|
45
|
+
async function bundleConfigFile(fileName) {
|
|
46
|
+
const result = await (0, import_esbuild.build)({
|
|
47
|
+
absWorkingDir: process.cwd(),
|
|
48
|
+
entryPoints: [fileName],
|
|
49
|
+
outfile: "out.js",
|
|
50
|
+
write: false,
|
|
51
|
+
platform: "node",
|
|
52
|
+
bundle: true,
|
|
53
|
+
format: "cjs",
|
|
54
|
+
sourcemap: false,
|
|
55
|
+
metafile: true,
|
|
56
|
+
mainFields: ["module", "main"]
|
|
57
|
+
});
|
|
58
|
+
const { text } = result.outputFiles[0];
|
|
59
|
+
return {
|
|
60
|
+
code: text,
|
|
61
|
+
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/load-bundled.ts
|
|
66
|
+
var import_fs = __toESM(require("fs"));
|
|
67
|
+
var import_path = __toESM(require("path"));
|
|
68
|
+
function loadBundledFile(fileName, code) {
|
|
69
|
+
const extension = import_path.default.extname(fileName);
|
|
70
|
+
const realFileName = import_fs.default.realpathSync(fileName);
|
|
71
|
+
const loader = require.extensions[extension];
|
|
72
|
+
require.extensions[extension] = (mod, filename) => {
|
|
73
|
+
if (filename === realFileName) {
|
|
74
|
+
mod._compile(code, filename);
|
|
75
|
+
} else {
|
|
76
|
+
loader(mod, filename);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
delete require.cache[require.resolve(fileName)];
|
|
80
|
+
const raw = require(fileName);
|
|
81
|
+
const config = raw.default ?? raw;
|
|
82
|
+
require.extensions[extension] = loader;
|
|
83
|
+
return config;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/bundle-require.ts
|
|
87
|
+
async function bundleAndRequire(filepath, cwd) {
|
|
88
|
+
const filePath = require.resolve(filepath, { paths: [cwd] });
|
|
89
|
+
let config;
|
|
90
|
+
let dependencies;
|
|
91
|
+
const end = import_logger.logger.time.debug(`Bundling config file ${(0, import_logger.quote)((0, import_path2.relative)(cwd, filePath))}`);
|
|
92
|
+
try {
|
|
93
|
+
const realFileName = (0, import_fs2.realpathSync)(filePath);
|
|
94
|
+
dependencies = [realFileName];
|
|
95
|
+
delete require.cache[filePath];
|
|
96
|
+
const mod = require(realFileName);
|
|
97
|
+
config = mod.default ?? mod;
|
|
98
|
+
} catch {
|
|
99
|
+
const bundle = await bundleConfigFile(filePath);
|
|
100
|
+
dependencies = bundle.dependencies;
|
|
101
|
+
try {
|
|
102
|
+
config = await loadBundledFile(filePath, bundle.code);
|
|
103
|
+
} catch {
|
|
104
|
+
config = require("node-eval")(bundle.code).default;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
end();
|
|
108
|
+
return {
|
|
109
|
+
config,
|
|
110
|
+
dependencies
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/find-config.ts
|
|
115
|
+
var import_sync = __toESM(require("escalade/sync"));
|
|
116
|
+
var import_path3 = require("path");
|
|
117
|
+
var configs = [".ts", ".js", ".mjs", ".cjs"];
|
|
118
|
+
function findConfigFile({ cwd, file }) {
|
|
119
|
+
if (file)
|
|
120
|
+
return (0, import_path3.resolve)(cwd, file);
|
|
121
|
+
return (0, import_sync.default)(cwd, (_dir, paths) => {
|
|
122
|
+
const regex = new RegExp(`panda.config(${configs.join("|")})$`);
|
|
123
|
+
return paths.find((p) => regex.test(p));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/load-config.ts
|
|
128
|
+
async function loadConfigFile(options) {
|
|
129
|
+
const { cwd, file } = options;
|
|
130
|
+
const filePath = findConfigFile({ cwd, file });
|
|
131
|
+
if (!filePath) {
|
|
132
|
+
throw new import_error.ConfigNotFoundError();
|
|
133
|
+
}
|
|
134
|
+
import_logger2.logger.debug({ type: "config", path: filePath });
|
|
135
|
+
const result = await bundleAndRequire(filePath, cwd);
|
|
136
|
+
if (typeof result.config !== "object") {
|
|
137
|
+
throw new import_error.ConfigError(`\u{1F4A5} Config must export or return an object.`);
|
|
138
|
+
}
|
|
139
|
+
const presets = result.config.presets ?? [];
|
|
140
|
+
for (const preset of presets) {
|
|
141
|
+
const presetResult = await bundleAndRequire(preset, cwd);
|
|
142
|
+
result.config = (0, import_merge_anything.merge)({}, result.config, presetResult.config);
|
|
143
|
+
}
|
|
144
|
+
delete result.config.presets;
|
|
145
|
+
return {
|
|
146
|
+
...result,
|
|
147
|
+
path: filePath
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
loadConfigFile
|
|
153
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/load-config.ts
|
|
10
|
+
import { ConfigNotFoundError, ConfigError } from "@pandacss/error";
|
|
11
|
+
import { logger as logger2 } from "@pandacss/logger";
|
|
12
|
+
import { merge } from "merge-anything";
|
|
13
|
+
|
|
14
|
+
// src/bundle-require.ts
|
|
15
|
+
import { logger, quote } from "@pandacss/logger";
|
|
16
|
+
import { realpathSync } from "fs";
|
|
17
|
+
import { relative } from "path";
|
|
18
|
+
|
|
19
|
+
// src/bundle-config.ts
|
|
20
|
+
import { build } from "esbuild";
|
|
21
|
+
async function bundleConfigFile(fileName) {
|
|
22
|
+
const result = await build({
|
|
23
|
+
absWorkingDir: process.cwd(),
|
|
24
|
+
entryPoints: [fileName],
|
|
25
|
+
outfile: "out.js",
|
|
26
|
+
write: false,
|
|
27
|
+
platform: "node",
|
|
28
|
+
bundle: true,
|
|
29
|
+
format: "cjs",
|
|
30
|
+
sourcemap: false,
|
|
31
|
+
metafile: true,
|
|
32
|
+
mainFields: ["module", "main"]
|
|
33
|
+
});
|
|
34
|
+
const { text } = result.outputFiles[0];
|
|
35
|
+
return {
|
|
36
|
+
code: text,
|
|
37
|
+
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/load-bundled.ts
|
|
42
|
+
import fs from "fs";
|
|
43
|
+
import path from "path";
|
|
44
|
+
function loadBundledFile(fileName, code) {
|
|
45
|
+
const extension = path.extname(fileName);
|
|
46
|
+
const realFileName = fs.realpathSync(fileName);
|
|
47
|
+
const loader = __require.extensions[extension];
|
|
48
|
+
__require.extensions[extension] = (mod, filename) => {
|
|
49
|
+
if (filename === realFileName) {
|
|
50
|
+
mod._compile(code, filename);
|
|
51
|
+
} else {
|
|
52
|
+
loader(mod, filename);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
delete __require.cache[__require.resolve(fileName)];
|
|
56
|
+
const raw = __require(fileName);
|
|
57
|
+
const config = raw.default ?? raw;
|
|
58
|
+
__require.extensions[extension] = loader;
|
|
59
|
+
return config;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/bundle-require.ts
|
|
63
|
+
async function bundleAndRequire(filepath, cwd) {
|
|
64
|
+
const filePath = __require.resolve(filepath, { paths: [cwd] });
|
|
65
|
+
let config;
|
|
66
|
+
let dependencies;
|
|
67
|
+
const end = logger.time.debug(`Bundling config file ${quote(relative(cwd, filePath))}`);
|
|
68
|
+
try {
|
|
69
|
+
const realFileName = realpathSync(filePath);
|
|
70
|
+
dependencies = [realFileName];
|
|
71
|
+
delete __require.cache[filePath];
|
|
72
|
+
const mod = __require(realFileName);
|
|
73
|
+
config = mod.default ?? mod;
|
|
74
|
+
} catch {
|
|
75
|
+
const bundle = await bundleConfigFile(filePath);
|
|
76
|
+
dependencies = bundle.dependencies;
|
|
77
|
+
try {
|
|
78
|
+
config = await loadBundledFile(filePath, bundle.code);
|
|
79
|
+
} catch {
|
|
80
|
+
config = __require("node-eval")(bundle.code).default;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
end();
|
|
84
|
+
return {
|
|
85
|
+
config,
|
|
86
|
+
dependencies
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/find-config.ts
|
|
91
|
+
import findUp from "escalade/sync";
|
|
92
|
+
import { resolve } from "path";
|
|
93
|
+
var configs = [".ts", ".js", ".mjs", ".cjs"];
|
|
94
|
+
function findConfigFile({ cwd, file }) {
|
|
95
|
+
if (file)
|
|
96
|
+
return resolve(cwd, file);
|
|
97
|
+
return findUp(cwd, (_dir, paths) => {
|
|
98
|
+
const regex = new RegExp(`panda.config(${configs.join("|")})$`);
|
|
99
|
+
return paths.find((p) => regex.test(p));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/load-config.ts
|
|
104
|
+
async function loadConfigFile(options) {
|
|
105
|
+
const { cwd, file } = options;
|
|
106
|
+
const filePath = findConfigFile({ cwd, file });
|
|
107
|
+
if (!filePath) {
|
|
108
|
+
throw new ConfigNotFoundError();
|
|
109
|
+
}
|
|
110
|
+
logger2.debug({ type: "config", path: filePath });
|
|
111
|
+
const result = await bundleAndRequire(filePath, cwd);
|
|
112
|
+
if (typeof result.config !== "object") {
|
|
113
|
+
throw new ConfigError(`\u{1F4A5} Config must export or return an object.`);
|
|
114
|
+
}
|
|
115
|
+
const presets = result.config.presets ?? [];
|
|
116
|
+
for (const preset of presets) {
|
|
117
|
+
const presetResult = await bundleAndRequire(preset, cwd);
|
|
118
|
+
result.config = merge({}, result.config, presetResult.config);
|
|
119
|
+
}
|
|
120
|
+
delete result.config.presets;
|
|
121
|
+
return {
|
|
122
|
+
...result,
|
|
123
|
+
path: filePath
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export {
|
|
127
|
+
loadConfigFile
|
|
128
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pandacss/config",
|
|
3
|
+
"version": "0.0.0-dev-20221121152823",
|
|
4
|
+
"description": "Find and load panda config",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"author": "Segun Adebayo <joseshegs@gmail.com>",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"merge-anything": "^5.0.4",
|
|
18
|
+
"esbuild": "0.15.15",
|
|
19
|
+
"escalade": "3.1.1",
|
|
20
|
+
"node-eval": "2.0.0",
|
|
21
|
+
"@pandacss/logger": "0.0.0-dev-20221121152823",
|
|
22
|
+
"@pandacss/error": "0.0.0-dev-20221121152823",
|
|
23
|
+
"@pandacss/types": "0.0.0-dev-20221121152823"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "pnpm tsup src/index.ts --format=esm,cjs --shims --dts",
|
|
27
|
+
"build-fast": "pnpm tsup src/index.ts --format=esm,cjs --shims --no-dts",
|
|
28
|
+
"dev": "pnpm build-fast --watch"
|
|
29
|
+
}
|
|
30
|
+
}
|