tailwindcss 0.0.0-oxide-insiders.694aea0 → 0.0.0-oxide-insiders.ac1738e
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/lib/cli/build/index.js +3 -2
- package/lib/cli/build/plugin.js +23 -18
- package/lib/cli/build/watching.js +1 -1
- package/lib/cli/index.js +12 -21
- package/lib/cli/init/index.js +21 -6
- package/lib/lib/getModuleDependencies.js +37 -25
- package/lib/lib/load-config.js +36 -0
- package/lib/lib/setupTrackingContext.js +4 -4
- package/lib/oxide/cli/build/index.js +3 -2
- package/lib/oxide/cli/build/plugin.js +22 -17
- package/lib/oxide/cli/build/watching.js +1 -1
- package/lib/oxide/cli/index.js +10 -16
- package/lib/oxide/cli/init/index.js +19 -4
- package/lib/public/default-config.js +2 -2
- package/lib/public/default-theme.js +2 -2
- package/lib/public/load-config.js +10 -0
- package/lib/util/getAllConfigs.js +2 -2
- package/lib/util/resolveConfigPath.js +19 -7
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/package.json +7 -5
- package/src/cli/build/index.js +3 -6
- package/src/cli/build/plugin.js +23 -22
- package/src/cli/build/watching.js +1 -1
- package/src/cli/index.js +8 -26
- package/src/cli/init/index.js +37 -8
- package/src/lib/getModuleDependencies.js +26 -25
- package/src/lib/load-config.ts +27 -0
- package/src/lib/setupTrackingContext.js +4 -4
- package/src/oxide/cli/build/index.ts +3 -6
- package/src/oxide/cli/build/plugin.ts +23 -21
- package/src/oxide/cli/build/watching.ts +1 -1
- package/src/oxide/cli/index.ts +7 -15
- package/src/oxide/cli/init/index.ts +34 -7
- package/src/public/default-config.js +1 -1
- package/src/public/default-theme.js +2 -2
- package/src/public/load-config.js +2 -0
- package/src/util/getAllConfigs.js +2 -2
- package/src/util/resolveConfigPath.js +12 -1
- package/stubs/.gitignore +1 -0
- package/stubs/.prettierrc.json +6 -0
- package/stubs/{defaultConfig.stub.js → config.full.js} +0 -1
- package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -1
- package/stubs/postcss.config.js +6 -0
- package/stubs/tailwind.config.cjs +2 -0
- package/stubs/tailwind.config.js +2 -0
- package/stubs/tailwind.config.ts +3 -0
- package/lib/constants.js +0 -44
- package/src/constants.js +0 -17
- /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
default: ()=>resolveConfigPath,
|
|
13
|
+
resolveDefaultConfigPath: ()=>resolveDefaultConfigPath
|
|
8
14
|
});
|
|
9
15
|
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
10
16
|
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
@@ -13,6 +19,12 @@ function _interopRequireDefault(obj) {
|
|
|
13
19
|
default: obj
|
|
14
20
|
};
|
|
15
21
|
}
|
|
22
|
+
const defaultConfigFiles = [
|
|
23
|
+
"./tailwind.config.js",
|
|
24
|
+
"./tailwind.config.cjs",
|
|
25
|
+
"./tailwind.config.mjs",
|
|
26
|
+
"./tailwind.config.ts"
|
|
27
|
+
];
|
|
16
28
|
function isObject(value) {
|
|
17
29
|
return typeof value === "object" && value !== null;
|
|
18
30
|
}
|
|
@@ -40,10 +52,10 @@ function resolveConfigPath(pathOrConfig) {
|
|
|
40
52
|
return _path.default.resolve(pathOrConfig);
|
|
41
53
|
}
|
|
42
54
|
// require('tailwindcss')
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
return resolveDefaultConfigPath();
|
|
56
|
+
}
|
|
57
|
+
function resolveDefaultConfigPath() {
|
|
58
|
+
for (const configFile of defaultConfigFiles){
|
|
47
59
|
try {
|
|
48
60
|
const configPath = _path.default.resolve(configFile);
|
|
49
61
|
_fs.default.accessSync(configPath);
|
package/loadConfig.d.ts
ADDED
package/loadConfig.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss",
|
|
3
|
-
"version": "0.0.0-oxide-insiders.
|
|
3
|
+
"version": "0.0.0-oxide-insiders.ac1738e",
|
|
4
4
|
"description": "A utility-first CSS framework for rapidly building custom user interfaces.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"lib/*",
|
|
41
41
|
"peers/*",
|
|
42
42
|
"scripts/*.js",
|
|
43
|
-
"stubs
|
|
43
|
+
"stubs/*",
|
|
44
44
|
"nesting/*",
|
|
45
45
|
"types/**/*",
|
|
46
46
|
"*.d.ts",
|
|
@@ -70,17 +70,18 @@
|
|
|
70
70
|
"postcss": "^8.0.9"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@tailwindcss/oxide": "0.0.0-oxide-insiders.
|
|
73
|
+
"@tailwindcss/oxide": "0.0.0-oxide-insiders.ac1738e",
|
|
74
74
|
"arg": "^5.0.2",
|
|
75
75
|
"browserslist": "^4.21.5",
|
|
76
76
|
"chokidar": "^3.5.3",
|
|
77
77
|
"color-name": "^1.1.4",
|
|
78
|
-
"detective": "^
|
|
78
|
+
"detective-typescript": "^9.0.0",
|
|
79
79
|
"didyoumean": "^1.2.2",
|
|
80
80
|
"dlv": "^1.1.3",
|
|
81
81
|
"fast-glob": "^3.2.12",
|
|
82
82
|
"glob-parent": "^6.0.2",
|
|
83
83
|
"is-glob": "^4.0.3",
|
|
84
|
+
"jiti": "^1.17.2",
|
|
84
85
|
"lightningcss": "^1.18.0",
|
|
85
86
|
"lilconfig": "^2.1.0",
|
|
86
87
|
"micromatch": "^4.0.5",
|
|
@@ -95,7 +96,8 @@
|
|
|
95
96
|
"postcss-selector-parser": "^6.0.11",
|
|
96
97
|
"postcss-value-parser": "^4.2.0",
|
|
97
98
|
"quick-lru": "^5.1.1",
|
|
98
|
-
"resolve": "^1.22.1"
|
|
99
|
+
"resolve": "^1.22.1",
|
|
100
|
+
"sucrase": "^3.29.0"
|
|
99
101
|
},
|
|
100
102
|
"browserslist": [
|
|
101
103
|
"> 1%",
|
package/src/cli/build/index.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import path from 'path'
|
|
5
|
+
import { resolveDefaultConfigPath } from '../../util/resolveConfigPath.js'
|
|
5
6
|
import { createProcessor } from './plugin.js'
|
|
6
7
|
|
|
7
|
-
export async function build(args
|
|
8
|
+
export async function build(args) {
|
|
8
9
|
let input = args['--input']
|
|
9
10
|
let shouldWatch = args['--watch']
|
|
10
11
|
|
|
@@ -25,11 +26,7 @@ export async function build(args, configs) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
// TODO: Reference the @config path here if exists
|
|
28
|
-
let configPath = args['--config']
|
|
29
|
-
? args['--config']
|
|
30
|
-
: ((defaultPath) => (fs.existsSync(defaultPath) ? defaultPath : null))(
|
|
31
|
-
path.resolve(`./${configs.tailwind}`)
|
|
32
|
-
)
|
|
29
|
+
let configPath = args['--config'] ? args['--config'] : resolveDefaultConfigPath()
|
|
33
30
|
|
|
34
31
|
let processor = await createProcessor(args, configPath)
|
|
35
32
|
|
package/src/cli/build/plugin.js
CHANGED
|
@@ -12,12 +12,13 @@ import { loadAutoprefixer, loadCssNano, loadPostcss, loadPostcssImport } from '.
|
|
|
12
12
|
import { formatNodes, drainStdin, outputFile } from './utils'
|
|
13
13
|
import { env } from '../../lib/sharedState'
|
|
14
14
|
import resolveConfig from '../../../resolveConfig.js'
|
|
15
|
-
import getModuleDependencies from '../../lib/getModuleDependencies.js'
|
|
16
15
|
import { parseCandidateFiles } from '../../lib/content.js'
|
|
17
16
|
import { createWatcher } from './watching.js'
|
|
18
17
|
import fastGlob from 'fast-glob'
|
|
19
18
|
import { findAtConfigPath } from '../../lib/findAtConfigPath.js'
|
|
20
19
|
import log from '../../util/log'
|
|
20
|
+
import { loadConfig } from '../../lib/load-config'
|
|
21
|
+
import getModuleDependencies from '../../lib/getModuleDependencies'
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
*
|
|
@@ -117,7 +118,9 @@ let state = {
|
|
|
117
118
|
/** @type {{content: string, extension: string}[]} */
|
|
118
119
|
changedContent: [],
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
/** @type {ReturnType<typeof load> | null} */
|
|
122
|
+
configBag: null,
|
|
123
|
+
|
|
121
124
|
contextDependencies: new Set(),
|
|
122
125
|
|
|
123
126
|
/** @type {import('../../lib/content.js').ContentPath[]} */
|
|
@@ -142,37 +145,35 @@ let state = {
|
|
|
142
145
|
|
|
143
146
|
loadConfig(configPath, content) {
|
|
144
147
|
if (this.watcher && configPath) {
|
|
145
|
-
this.refreshConfigDependencies(
|
|
148
|
+
this.refreshConfigDependencies()
|
|
146
149
|
}
|
|
147
150
|
|
|
148
|
-
let config =
|
|
151
|
+
let config = loadConfig(configPath)
|
|
152
|
+
let dependencies = getModuleDependencies(configPath)
|
|
153
|
+
this.configBag = {
|
|
154
|
+
config,
|
|
155
|
+
dependencies,
|
|
156
|
+
dispose() {
|
|
157
|
+
for (let file of dependencies) {
|
|
158
|
+
delete require.cache[require.resolve(file)]
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
}
|
|
149
162
|
|
|
150
163
|
// @ts-ignore
|
|
151
|
-
config = resolveConfig(config, { content: { files: [] } })
|
|
164
|
+
this.configBag.config = resolveConfig(this.configBag.config, { content: { files: [] } })
|
|
152
165
|
|
|
153
166
|
// Override content files if `--content` has been passed explicitly
|
|
154
167
|
if (content?.length > 0) {
|
|
155
|
-
config.content.files = content
|
|
168
|
+
this.configBag.config.content.files = content
|
|
156
169
|
}
|
|
157
170
|
|
|
158
|
-
return config
|
|
171
|
+
return this.configBag.config
|
|
159
172
|
},
|
|
160
173
|
|
|
161
|
-
refreshConfigDependencies(
|
|
174
|
+
refreshConfigDependencies() {
|
|
162
175
|
env.DEBUG && console.time('Module dependencies')
|
|
163
|
-
|
|
164
|
-
for (let file of this.configDependencies) {
|
|
165
|
-
delete require.cache[require.resolve(file)]
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (configPath) {
|
|
169
|
-
let deps = getModuleDependencies(configPath).map(({ file }) => file)
|
|
170
|
-
|
|
171
|
-
for (let dependency of deps) {
|
|
172
|
-
this.configDependencies.add(dependency)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
+
this.configBag?.dispose()
|
|
176
177
|
env.DEBUG && console.timeEnd('Module dependencies')
|
|
177
178
|
},
|
|
178
179
|
|
|
@@ -420,7 +421,7 @@ export async function createProcessor(args, cliConfigPath) {
|
|
|
420
421
|
async rebuild(changes) {
|
|
421
422
|
let needsNewContext = changes.some((change) => {
|
|
422
423
|
return (
|
|
423
|
-
state.
|
|
424
|
+
state.configBag?.dependencies.has(change.file) ||
|
|
424
425
|
state.contextDependencies.has(change.file)
|
|
425
426
|
)
|
|
426
427
|
})
|
|
@@ -220,7 +220,7 @@ export function createWatcher(args, { state, rebuild }) {
|
|
|
220
220
|
|
|
221
221
|
refreshWatchedFiles() {
|
|
222
222
|
watcher.add(Array.from(state.contextDependencies))
|
|
223
|
-
watcher.add(Array.from(state.
|
|
223
|
+
watcher.add(Array.from(state.configBag.dependencies))
|
|
224
224
|
watcher.add(state.contentPatterns.all)
|
|
225
225
|
},
|
|
226
226
|
}
|
package/src/cli/index.js
CHANGED
|
@@ -8,29 +8,6 @@ import { build } from './build'
|
|
|
8
8
|
import { help } from './help'
|
|
9
9
|
import { init } from './init'
|
|
10
10
|
|
|
11
|
-
function isESM() {
|
|
12
|
-
const pkgPath = path.resolve('./package.json')
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
16
|
-
return pkg.type && pkg.type === 'module'
|
|
17
|
-
} catch (err) {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let configs = isESM()
|
|
23
|
-
? {
|
|
24
|
-
tailwind: 'tailwind.config.cjs',
|
|
25
|
-
postcss: 'postcss.config.cjs',
|
|
26
|
-
}
|
|
27
|
-
: {
|
|
28
|
-
tailwind: 'tailwind.config.js',
|
|
29
|
-
postcss: 'postcss.config.js',
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ---
|
|
33
|
-
|
|
34
11
|
function oneOf(...options) {
|
|
35
12
|
return Object.assign(
|
|
36
13
|
(value = true) => {
|
|
@@ -51,8 +28,13 @@ let commands = {
|
|
|
51
28
|
init: {
|
|
52
29
|
run: init,
|
|
53
30
|
args: {
|
|
54
|
-
'--
|
|
55
|
-
'--
|
|
31
|
+
'--esm': { type: Boolean, description: `Initialize configuration file as ESM` },
|
|
32
|
+
'--ts': { type: Boolean, description: `Initialize configuration file as TypeScript` },
|
|
33
|
+
'--postcss': { type: Boolean, description: `Initialize a \`postcss.config.js\` file` },
|
|
34
|
+
'--full': {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
description: `Include the default values for all options in the generated configuration file`,
|
|
37
|
+
},
|
|
56
38
|
'-f': '--full',
|
|
57
39
|
'-p': '--postcss',
|
|
58
40
|
},
|
|
@@ -231,4 +213,4 @@ if (args['--help']) {
|
|
|
231
213
|
process.exit(0)
|
|
232
214
|
}
|
|
233
215
|
|
|
234
|
-
run(args
|
|
216
|
+
run(args)
|
package/src/cli/init/index.js
CHANGED
|
@@ -3,22 +3,49 @@
|
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import path from 'path'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function isESM() {
|
|
7
|
+
const pkgPath = path.resolve('./package.json')
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
11
|
+
return pkg.type && pkg.type === 'module'
|
|
12
|
+
} catch (err) {
|
|
13
|
+
return false
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function init(args) {
|
|
7
18
|
let messages = []
|
|
8
19
|
|
|
9
|
-
let
|
|
20
|
+
let isProjectESM = args['--ts'] || args['--esm'] || isESM()
|
|
21
|
+
let syntax = args['--ts'] ? 'ts' : isProjectESM ? 'js' : 'cjs'
|
|
22
|
+
let extension = args['--ts'] ? 'ts' : 'js'
|
|
23
|
+
|
|
24
|
+
let tailwindConfigLocation = path.resolve(args['_'][1] ?? `./tailwind.config.${extension}`)
|
|
25
|
+
|
|
10
26
|
if (fs.existsSync(tailwindConfigLocation)) {
|
|
11
27
|
messages.push(`${path.basename(tailwindConfigLocation)} already exists.`)
|
|
12
28
|
} else {
|
|
13
|
-
let
|
|
29
|
+
let stubContentsFile = fs.readFileSync(
|
|
14
30
|
args['--full']
|
|
15
|
-
? path.resolve(__dirname, '../../../stubs/
|
|
16
|
-
: path.resolve(__dirname, '../../../stubs/
|
|
31
|
+
? path.resolve(__dirname, '../../../stubs/config.full.js')
|
|
32
|
+
: path.resolve(__dirname, '../../../stubs/config.simple.js'),
|
|
33
|
+
'utf8'
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
let stubFile = fs.readFileSync(
|
|
37
|
+
path.resolve(__dirname, `../../../stubs/tailwind.config.${syntax}`),
|
|
17
38
|
'utf8'
|
|
18
39
|
)
|
|
19
40
|
|
|
20
41
|
// Change colors import
|
|
21
|
-
|
|
42
|
+
stubContentsFile = stubContentsFile.replace('../colors', 'tailwindcss/colors')
|
|
43
|
+
|
|
44
|
+
// Replace contents of {ts,js,cjs} file with the stub {simple,full}.
|
|
45
|
+
stubFile =
|
|
46
|
+
stubFile
|
|
47
|
+
.replace('__CONFIG__', stubContentsFile.replace('module.exports =', '').trim())
|
|
48
|
+
.trim() + '\n\n'
|
|
22
49
|
|
|
23
50
|
fs.writeFileSync(tailwindConfigLocation, stubFile, 'utf8')
|
|
24
51
|
|
|
@@ -26,12 +53,14 @@ export function init(args, configs) {
|
|
|
26
53
|
}
|
|
27
54
|
|
|
28
55
|
if (args['--postcss']) {
|
|
29
|
-
let postcssConfigLocation = path.resolve(
|
|
56
|
+
let postcssConfigLocation = path.resolve('./postcss.config.js')
|
|
30
57
|
if (fs.existsSync(postcssConfigLocation)) {
|
|
31
58
|
messages.push(`${path.basename(postcssConfigLocation)} already exists.`)
|
|
32
59
|
} else {
|
|
33
60
|
let stubFile = fs.readFileSync(
|
|
34
|
-
|
|
61
|
+
isProjectESM
|
|
62
|
+
? path.resolve(__dirname, '../../../stubs/postcss.config.js')
|
|
63
|
+
: path.resolve(__dirname, '../../../stubs/postcss.config.cjs'),
|
|
35
64
|
'utf8'
|
|
36
65
|
)
|
|
37
66
|
|
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import resolve from 'resolve'
|
|
4
|
-
import detective from 'detective'
|
|
4
|
+
import detective from 'detective-typescript'
|
|
5
5
|
|
|
6
6
|
function createModule(file) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return { file, requires }
|
|
7
|
+
let source = fs.readFileSync(file, 'utf-8')
|
|
8
|
+
return { file, requires: detective(source, { mixedImports: true }) }
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
function* _getModuleDependencies(entryFile) {
|
|
12
|
+
yield entryFile
|
|
13
|
+
|
|
14
|
+
let mod = createModule(entryFile)
|
|
15
|
+
|
|
16
|
+
let ext = path.extname(entryFile)
|
|
17
|
+
let isTypeScript = ext === '.ts' || ext === '.cts' || ext === '.mts'
|
|
18
|
+
let extensions = [...(isTypeScript ? ['.ts', '.cts', '.mts'] : []), '.js', '.cjs', '.mjs']
|
|
16
19
|
|
|
17
20
|
// Iterate over the modules, even when new
|
|
18
21
|
// ones are being added
|
|
19
|
-
for (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})
|
|
25
|
-
.forEach((dep) => {
|
|
26
|
-
try {
|
|
27
|
-
const basedir = path.dirname(mdl.file)
|
|
28
|
-
const depPath = resolve.sync(dep, { basedir })
|
|
29
|
-
const depModule = createModule(depPath)
|
|
22
|
+
for (let dep of mod.requires) {
|
|
23
|
+
// Only track local modules, not node_modules
|
|
24
|
+
if (!dep.startsWith('./') && !dep.startsWith('../')) {
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
try {
|
|
29
|
+
let basedir = path.dirname(mod.file)
|
|
30
|
+
let depPath = resolve.sync(dep, { basedir, extensions })
|
|
31
|
+
yield* _getModuleDependencies(depPath)
|
|
32
|
+
} catch (_err) {
|
|
33
|
+
// eslint-disable-next-line no-empty
|
|
34
|
+
}
|
|
36
35
|
}
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
export default function getModuleDependencies(entryFile) {
|
|
39
|
+
return new Set(_getModuleDependencies(entryFile))
|
|
39
40
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import jitiFactory from 'jiti'
|
|
2
|
+
import { transform } from 'sucrase'
|
|
3
|
+
|
|
4
|
+
import { Config } from '../../types/config'
|
|
5
|
+
|
|
6
|
+
let jiti: ReturnType<typeof jitiFactory> | null = null
|
|
7
|
+
function lazyJiti() {
|
|
8
|
+
return (
|
|
9
|
+
jiti ??
|
|
10
|
+
(jiti = jitiFactory(__filename, {
|
|
11
|
+
interopDefault: true,
|
|
12
|
+
transform: (opts) => {
|
|
13
|
+
return transform(opts.source, {
|
|
14
|
+
transforms: ['typescript', 'imports'],
|
|
15
|
+
})
|
|
16
|
+
},
|
|
17
|
+
}))
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function loadConfig(path: string): Config {
|
|
22
|
+
try {
|
|
23
|
+
return path ? require(path) : {}
|
|
24
|
+
} catch {
|
|
25
|
+
return lazyJiti()(path)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -4,13 +4,14 @@ import fs from 'fs'
|
|
|
4
4
|
import LRU from 'quick-lru'
|
|
5
5
|
|
|
6
6
|
import hash from '../util/hashConfig'
|
|
7
|
-
import getModuleDependencies from '../lib/getModuleDependencies'
|
|
8
7
|
import resolveConfig from '../public/resolve-config'
|
|
9
8
|
import resolveConfigPath from '../util/resolveConfigPath'
|
|
10
9
|
import { getContext, getFileModifiedMap } from './setupContextUtils'
|
|
11
10
|
import parseDependency from '../util/parseDependency'
|
|
12
11
|
import { validateConfig } from '../util/validateConfig.js'
|
|
13
12
|
import { parseCandidateFiles, resolvedChangedContent } from './content.js'
|
|
13
|
+
import { loadConfig } from '../lib/load-config'
|
|
14
|
+
import getModuleDependencies from './getModuleDependencies'
|
|
14
15
|
|
|
15
16
|
let configPathCache = new LRU({ maxSize: 100 })
|
|
16
17
|
|
|
@@ -34,7 +35,7 @@ function getTailwindConfig(configOrPath) {
|
|
|
34
35
|
let [prevConfig, prevConfigHash, prevDeps, prevModified] =
|
|
35
36
|
configPathCache.get(userConfigPath) || []
|
|
36
37
|
|
|
37
|
-
let newDeps = getModuleDependencies(userConfigPath)
|
|
38
|
+
let newDeps = getModuleDependencies(userConfigPath)
|
|
38
39
|
|
|
39
40
|
let modified = false
|
|
40
41
|
let newModified = new Map()
|
|
@@ -55,8 +56,7 @@ function getTailwindConfig(configOrPath) {
|
|
|
55
56
|
for (let file of newDeps) {
|
|
56
57
|
delete require.cache[file]
|
|
57
58
|
}
|
|
58
|
-
let newConfig = resolveConfig(
|
|
59
|
-
newConfig = validateConfig(newConfig)
|
|
59
|
+
let newConfig = validateConfig(resolveConfig(loadConfig(userConfigPath)))
|
|
60
60
|
let newHash = hash(newConfig)
|
|
61
61
|
configPathCache.set(userConfigPath, [newConfig, newHash, newDeps, newModified])
|
|
62
62
|
return [newConfig, userConfigPath, newHash, newDeps]
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
+
import { resolveDefaultConfigPath } from '../../../util/resolveConfigPath'
|
|
3
4
|
import { createProcessor } from './plugin'
|
|
4
5
|
|
|
5
|
-
export async function build(args
|
|
6
|
+
export async function build(args) {
|
|
6
7
|
let input = args['--input']
|
|
7
8
|
let shouldWatch = args['--watch']
|
|
8
9
|
|
|
@@ -23,11 +24,7 @@ export async function build(args, configs) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// TODO: Reference the @config path here if exists
|
|
26
|
-
let configPath = args['--config']
|
|
27
|
-
? args['--config']
|
|
28
|
-
: ((defaultPath) => (fs.existsSync(defaultPath) ? defaultPath : null))(
|
|
29
|
-
path.resolve(`./${configs.tailwind}`)
|
|
30
|
-
)
|
|
27
|
+
let configPath = args['--config'] ? args['--config'] : resolveDefaultConfigPath()
|
|
31
28
|
|
|
32
29
|
let processor = await createProcessor(args, configPath)
|
|
33
30
|
|
|
@@ -10,12 +10,14 @@ import { loadPostcss, loadPostcssImport, lightningcss } from './deps'
|
|
|
10
10
|
import { formatNodes, drainStdin, outputFile } from './utils'
|
|
11
11
|
import { env } from '../../../lib/sharedState'
|
|
12
12
|
import resolveConfig from '../../../../resolveConfig'
|
|
13
|
-
import getModuleDependencies from '../../../lib/getModuleDependencies'
|
|
14
13
|
import { parseCandidateFiles } from '../../../lib/content'
|
|
15
14
|
import { createWatcher } from './watching'
|
|
16
15
|
import fastGlob from 'fast-glob'
|
|
17
16
|
import { findAtConfigPath } from '../../../lib/findAtConfigPath'
|
|
18
17
|
import log from '../../../util/log'
|
|
18
|
+
import { loadConfig } from '../../../lib/load-config'
|
|
19
|
+
import getModuleDependencies from '../../../lib/getModuleDependencies'
|
|
20
|
+
import type { Config } from '../../../../types'
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
*
|
|
@@ -115,7 +117,9 @@ let state = {
|
|
|
115
117
|
/** @type {{content: string, extension: string}[]} */
|
|
116
118
|
changedContent: [],
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
/** @type {{config: Config, dependencies: Set<string>, dispose: Function } | null} */
|
|
121
|
+
configBag: null,
|
|
122
|
+
|
|
119
123
|
contextDependencies: new Set(),
|
|
120
124
|
|
|
121
125
|
/** @type {import('../../lib/content.js').ContentPath[]} */
|
|
@@ -140,37 +144,35 @@ let state = {
|
|
|
140
144
|
|
|
141
145
|
loadConfig(configPath, content) {
|
|
142
146
|
if (this.watcher && configPath) {
|
|
143
|
-
this.refreshConfigDependencies(
|
|
147
|
+
this.refreshConfigDependencies()
|
|
144
148
|
}
|
|
145
149
|
|
|
146
|
-
let config =
|
|
150
|
+
let config = loadConfig(configPath)
|
|
151
|
+
let dependencies = getModuleDependencies(configPath)
|
|
152
|
+
this.configBag = {
|
|
153
|
+
config,
|
|
154
|
+
dependencies,
|
|
155
|
+
dispose() {
|
|
156
|
+
for (let file of dependencies) {
|
|
157
|
+
delete require.cache[require.resolve(file)]
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
}
|
|
147
161
|
|
|
148
162
|
// @ts-ignore
|
|
149
|
-
config = resolveConfig(config, { content: { files: [] } })
|
|
163
|
+
this.configBag.config = resolveConfig(this.configBag.config, { content: { files: [] } })
|
|
150
164
|
|
|
151
165
|
// Override content files if `--content` has been passed explicitly
|
|
152
166
|
if (content?.length > 0) {
|
|
153
|
-
config.content.files = content
|
|
167
|
+
this.configBag.config.content.files = content
|
|
154
168
|
}
|
|
155
169
|
|
|
156
|
-
return config
|
|
170
|
+
return this.configBag.config
|
|
157
171
|
},
|
|
158
172
|
|
|
159
173
|
refreshConfigDependencies(configPath) {
|
|
160
174
|
env.DEBUG && console.time('Module dependencies')
|
|
161
|
-
|
|
162
|
-
for (let file of this.configDependencies) {
|
|
163
|
-
delete require.cache[require.resolve(file)]
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (configPath) {
|
|
167
|
-
let deps = getModuleDependencies(configPath).map(({ file }) => file)
|
|
168
|
-
|
|
169
|
-
for (let dependency of deps) {
|
|
170
|
-
this.configDependencies.add(dependency)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
175
|
+
this.configBag?.dispose()
|
|
174
176
|
env.DEBUG && console.timeEnd('Module dependencies')
|
|
175
177
|
},
|
|
176
178
|
|
|
@@ -417,7 +419,7 @@ export async function createProcessor(args, cliConfigPath) {
|
|
|
417
419
|
async rebuild(changes) {
|
|
418
420
|
let needsNewContext = changes.some((change) => {
|
|
419
421
|
return (
|
|
420
|
-
state.
|
|
422
|
+
state.configBag?.dependencies.has(change.file) ||
|
|
421
423
|
state.contextDependencies.has(change.file)
|
|
422
424
|
)
|
|
423
425
|
})
|
|
@@ -218,7 +218,7 @@ export function createWatcher(args, { state, rebuild }) {
|
|
|
218
218
|
|
|
219
219
|
refreshWatchedFiles() {
|
|
220
220
|
watcher.add(Array.from(state.contextDependencies))
|
|
221
|
-
watcher.add(Array.from(state.
|
|
221
|
+
watcher.add(Array.from(state.configBag.dependencies))
|
|
222
222
|
watcher.add(state.contentPatterns.all)
|
|
223
223
|
},
|
|
224
224
|
}
|
package/src/oxide/cli/index.ts
CHANGED
|
@@ -8,19 +8,6 @@ import { build } from './build'
|
|
|
8
8
|
import { help } from './help'
|
|
9
9
|
import { init } from './init'
|
|
10
10
|
|
|
11
|
-
function isESM() {
|
|
12
|
-
const pkgPath = path.resolve('./package.json')
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
16
|
-
return pkg.type && pkg.type === 'module'
|
|
17
|
-
} catch (err) {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let configs = isESM() ? { tailwind: 'tailwind.config.cjs' } : { tailwind: 'tailwind.config.js' }
|
|
23
|
-
|
|
24
11
|
// ---
|
|
25
12
|
|
|
26
13
|
function oneOf(...options) {
|
|
@@ -43,7 +30,12 @@ let commands = {
|
|
|
43
30
|
init: {
|
|
44
31
|
run: init,
|
|
45
32
|
args: {
|
|
46
|
-
'--
|
|
33
|
+
'--esm': { type: Boolean, description: `Initialize configuration file as ESM` },
|
|
34
|
+
'--ts': { type: Boolean, description: `Initialize configuration file as TypeScript` },
|
|
35
|
+
'--full': {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
description: `Include the default values for all options in the generated configuration file`,
|
|
38
|
+
},
|
|
47
39
|
'-f': '--full',
|
|
48
40
|
},
|
|
49
41
|
},
|
|
@@ -209,4 +201,4 @@ if (args['--help']) {
|
|
|
209
201
|
process.exit(0)
|
|
210
202
|
}
|
|
211
203
|
|
|
212
|
-
run(args
|
|
204
|
+
run(args)
|