tailwindcss 0.0.0-insiders.d6e6ff6 → 0.0.0-insiders.d77b9ce

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/lib/cli/build/deps.js +54 -0
  3. package/lib/cli/build/index.js +44 -0
  4. package/lib/cli/build/plugin.js +317 -0
  5. package/lib/cli/build/utils.js +78 -0
  6. package/lib/cli/build/watching.js +113 -0
  7. package/lib/cli/help/index.js +71 -0
  8. package/lib/cli/index.js +18 -0
  9. package/lib/cli/init/index.js +46 -0
  10. package/lib/cli/shared.js +12 -0
  11. package/lib/cli.js +10 -655
  12. package/lib/corePlugins.js +6 -0
  13. package/lib/featureFlags.js +3 -2
  14. package/lib/index.js +5 -0
  15. package/lib/lib/content.js +162 -0
  16. package/lib/lib/evaluateTailwindFunctions.js +17 -1
  17. package/lib/lib/expandApplyAtRules.js +6 -11
  18. package/lib/lib/expandTailwindAtRules.js +8 -37
  19. package/lib/lib/findAtConfigPath.js +44 -0
  20. package/lib/lib/generateRules.js +8 -12
  21. package/lib/lib/offsets.js +199 -0
  22. package/lib/lib/setupContextUtils.js +100 -70
  23. package/lib/lib/setupTrackingContext.js +5 -41
  24. package/lib/util/dataTypes.js +7 -11
  25. package/lib/util/formatVariantSelector.js +92 -8
  26. package/lib/util/negateValue.js +15 -2
  27. package/lib/util/normalizeConfig.js +15 -1
  28. package/lib/util/parseBoxShadowValue.js +1 -1
  29. package/lib/util/parseDependency.js +33 -54
  30. package/lib/util/parseGlob.js +34 -0
  31. package/lib/util/resolveConfig.js +1 -1
  32. package/lib/util/splitAtTopLevelOnly.js +31 -81
  33. package/lib/util/transformThemeValue.js +8 -1
  34. package/package.json +5 -5
  35. package/peers/index.js +652 -662
  36. package/src/cli/build/deps.js +56 -0
  37. package/src/cli/build/index.js +45 -0
  38. package/src/cli/build/plugin.js +372 -0
  39. package/src/cli/build/utils.js +76 -0
  40. package/src/cli/build/watching.js +134 -0
  41. package/src/cli/help/index.js +70 -0
  42. package/src/cli/index.js +3 -0
  43. package/src/cli/init/index.js +50 -0
  44. package/src/cli/shared.js +5 -0
  45. package/src/cli.js +4 -777
  46. package/src/corePlugins.js +2 -0
  47. package/src/featureFlags.js +6 -1
  48. package/src/index.js +5 -0
  49. package/src/lib/content.js +199 -0
  50. package/src/lib/evaluateTailwindFunctions.js +22 -1
  51. package/src/lib/expandApplyAtRules.js +5 -11
  52. package/src/lib/expandTailwindAtRules.js +7 -41
  53. package/src/lib/findAtConfigPath.js +50 -0
  54. package/src/lib/generateRules.js +10 -12
  55. package/src/lib/offsets.js +239 -0
  56. package/src/lib/setupContextUtils.js +114 -71
  57. package/src/lib/setupTrackingContext.js +4 -45
  58. package/src/util/dataTypes.js +7 -9
  59. package/src/util/formatVariantSelector.js +113 -9
  60. package/src/util/negateValue.js +10 -2
  61. package/src/util/normalizeConfig.js +22 -2
  62. package/src/util/parseBoxShadowValue.js +1 -1
  63. package/src/util/parseDependency.js +37 -42
  64. package/src/util/parseGlob.js +24 -0
  65. package/src/util/resolveConfig.js +1 -1
  66. package/src/util/splitAtTopLevelOnly.js +23 -49
  67. package/src/util/transformThemeValue.js +9 -1
  68. package/stubs/defaultConfig.stub.js +9 -3
  69. package/types/config.d.ts +18 -5
package/CHANGELOG.md CHANGED
@@ -9,10 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
+ - Add new `break-keep` utility for `word-break: keep-all` ([#9393](https://github.com/tailwindlabs/tailwindcss/pull/9393))
12
13
  - Add support for configuring default `font-feature-settings` for a font family ([#9039](https://github.com/tailwindlabs/tailwindcss/pull/9039))
13
14
  - Add a standalone CLI build for 32-bit Linux on ARM (`node16-linux-armv7`) ([#9084](https://github.com/tailwindlabs/tailwindcss/pull/9084))
14
15
  - Add future flag to disable color opacity utility plugins ([#9088](https://github.com/tailwindlabs/tailwindcss/pull/9088))
15
16
  - Add negative value support for `outline-offset` ([#9136](https://github.com/tailwindlabs/tailwindcss/pull/9136))
17
+ - Allow negating utilities using min/max/clamp ([#9237](https://github.com/tailwindlabs/tailwindcss/pull/9237))
18
+ - Add new `collapse` utility for `visibility: collapse` ([#9181](https://github.com/tailwindlabs/tailwindcss/pull/9181))
19
+ - Allow resolving content paths relative to the config file ([#9396](https://github.com/tailwindlabs/tailwindcss/pull/9396))
20
+ - Add `@config` support ([#9405](https://github.com/tailwindlabs/tailwindcss/pull/9405))
16
21
 
17
22
  ### Fixed
18
23
 
@@ -21,9 +26,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
26
  - Sort tags before classes when `@applying` a selector with joined classes ([#9107](https://github.com/tailwindlabs/tailwindcss/pull/9107))
22
27
  - Remove invalid `outline-hidden` utility ([#9147](https://github.com/tailwindlabs/tailwindcss/pull/9147))
23
28
  - Honor the `hidden` attribute on elements in preflight ([#9174](https://github.com/tailwindlabs/tailwindcss/pull/9174))
24
- - Don't stop watching atomically renamed files ([#9173](https://github.com/tailwindlabs/tailwindcss/pull/9173))
29
+ - Don't stop watching atomically renamed files ([#9173](https://github.com/tailwindlabs/tailwindcss/pull/9173), [#9215](https://github.com/tailwindlabs/tailwindcss/pull/9215))
25
30
  - Re-use existing entries in the rule cache ([#9208](https://github.com/tailwindlabs/tailwindcss/pull/9208))
26
31
  - Don't output duplicate utilities ([#9208](https://github.com/tailwindlabs/tailwindcss/pull/9208))
32
+ - Fix `fontFamily` config TypeScript types ([#9214](https://github.com/tailwindlabs/tailwindcss/pull/9214))
33
+ - Handle variants on complex selector utilities ([#9262](https://github.com/tailwindlabs/tailwindcss/pull/9262))
34
+ - Don't mutate shared config objects ([#9294](https://github.com/tailwindlabs/tailwindcss/pull/9294))
35
+ - Fix ordering of parallel variants ([#9282](https://github.com/tailwindlabs/tailwindcss/pull/9282))
36
+ - Handle variants in utility selectors using `:where()` and `:has()` ([#9309](https://github.com/tailwindlabs/tailwindcss/pull/9309))
37
+ - Improve data type analyses for arbitrary values ([#9320](https://github.com/tailwindlabs/tailwindcss/pull/9320))
38
+ - Don't emit generated utilities with invalid uses of theme functions ([#9319](https://github.com/tailwindlabs/tailwindcss/pull/9319))
39
+ - Revert change that only listened for stdin close on TTYs ([#9331](https://github.com/tailwindlabs/tailwindcss/pull/9331))
40
+ - Ignore unset values (like `null` or `undefined`) when resolving the classList for intellisense ([#9385](https://github.com/tailwindlabs/tailwindcss/pull/9385))
27
41
 
28
42
  ## [3.1.8] - 2022-08-05
29
43
 
@@ -473,7 +487,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
473
487
 
474
488
  ### Fixed
475
489
 
476
- - Ensure `corePlugins` order is consisent in AOT mode ([#5928](https://github.com/tailwindlabs/tailwindcss/pull/5928))
490
+ - Ensure `corePlugins` order is consistent in AOT mode ([#5928](https://github.com/tailwindlabs/tailwindcss/pull/5928))
477
491
 
478
492
  ## [2.2.18] - 2021-10-29
479
493
 
@@ -0,0 +1,54 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ loadPostcss: ()=>loadPostcss,
14
+ loadPostcssImport: ()=>loadPostcssImport,
15
+ loadCssNano: ()=>loadCssNano,
16
+ loadAutoprefixer: ()=>loadAutoprefixer
17
+ });
18
+ const _indexJs = require("../../../peers/index.js");
19
+ function loadPostcss() {
20
+ // Try to load a local `postcss` version first
21
+ try {
22
+ return require("postcss");
23
+ } catch {}
24
+ return (0, _indexJs.lazyPostcss)();
25
+ }
26
+ function loadPostcssImport() {
27
+ // Try to load a local `postcss-import` version first
28
+ try {
29
+ return require("postcss-import");
30
+ } catch {}
31
+ return (0, _indexJs.lazyPostcssImport)();
32
+ }
33
+ function loadCssNano() {
34
+ let options = {
35
+ preset: [
36
+ "default",
37
+ {
38
+ cssDeclarationSorter: false
39
+ }
40
+ ]
41
+ };
42
+ // Try to load a local `cssnano` version first
43
+ try {
44
+ return require("cssnano");
45
+ } catch {}
46
+ return (0, _indexJs.lazyCssnano)()(options);
47
+ }
48
+ function loadAutoprefixer() {
49
+ // Try to load a local `autoprefixer` version first
50
+ try {
51
+ return require("autoprefixer");
52
+ } catch {}
53
+ return (0, _indexJs.lazyAutoprefixer)();
54
+ }
@@ -0,0 +1,44 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "build", {
7
+ enumerable: true,
8
+ get: ()=>build
9
+ });
10
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
11
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
12
+ const _pluginJs = require("./plugin.js");
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ async function build(args, configs) {
19
+ let input = args["--input"];
20
+ let shouldWatch = args["--watch"];
21
+ // TODO: Deprecate this in future versions
22
+ if (!input && args["_"][1]) {
23
+ console.error("[deprecation] Running tailwindcss without -i, please provide an input file.");
24
+ input = args["--input"] = args["_"][1];
25
+ }
26
+ if (input && input !== "-" && !_fs.default.existsSync(input = _path.default.resolve(input))) {
27
+ console.error(`Specified input file ${args["--input"]} does not exist.`);
28
+ process.exit(9);
29
+ }
30
+ if (args["--config"] && !_fs.default.existsSync(args["--config"] = _path.default.resolve(args["--config"]))) {
31
+ console.error(`Specified config file ${args["--config"]} does not exist.`);
32
+ process.exit(9);
33
+ }
34
+ // TODO: Reference the @config path here if exists
35
+ let configPath = args["--config"] ? args["--config"] : ((defaultPath)=>_fs.default.existsSync(defaultPath) ? defaultPath : null)(_path.default.resolve(`./${configs.tailwind}`));
36
+ let processor = await (0, _pluginJs.createProcessor)(args, configPath);
37
+ if (shouldWatch) {
38
+ /* Abort the watcher if stdin is closed to avoid zombie processes */ process.stdin.on("end", ()=>process.exit(0));
39
+ process.stdin.resume();
40
+ await processor.watch();
41
+ } else {
42
+ await processor.build();
43
+ }
44
+ }
@@ -0,0 +1,317 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "createProcessor", {
7
+ enumerable: true,
8
+ get: ()=>createProcessor
9
+ });
10
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
11
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
12
+ const _postcssLoadConfig = /*#__PURE__*/ _interopRequireDefault(require("postcss-load-config"));
13
+ const _lilconfig = require("lilconfig");
14
+ const _plugins = /*#__PURE__*/ _interopRequireDefault(require("postcss-load-config/src/plugins" // Little bit scary, looking at private/internal API
15
+ ));
16
+ const _options = /*#__PURE__*/ _interopRequireDefault(require("postcss-load-config/src/options" // Little bit scary, looking at private/internal API
17
+ ));
18
+ const _processTailwindFeatures = /*#__PURE__*/ _interopRequireDefault(require("../../processTailwindFeatures"));
19
+ const _deps = require("./deps");
20
+ const _utils = require("./utils");
21
+ const _shared = require("../shared");
22
+ const _resolveConfigJs = /*#__PURE__*/ _interopRequireDefault(require("../../../resolveConfig.js"));
23
+ const _getModuleDependenciesJs = /*#__PURE__*/ _interopRequireDefault(require("../../lib/getModuleDependencies.js"));
24
+ const _contentJs = require("../../lib/content.js");
25
+ const _watchingJs = require("./watching.js");
26
+ const _fastGlob = /*#__PURE__*/ _interopRequireDefault(require("fast-glob"));
27
+ const _findAtConfigPathJs = require("../../lib/findAtConfigPath.js");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ /**
34
+ *
35
+ * @param {string} [customPostCssPath ]
36
+ * @returns
37
+ */ async function loadPostCssPlugins(customPostCssPath) {
38
+ let config = customPostCssPath ? await (async ()=>{
39
+ let file = _path.default.resolve(customPostCssPath);
40
+ // Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
41
+ // @ts-ignore
42
+ let { config ={} } = await (0, _lilconfig.lilconfig)("postcss").load(file);
43
+ if (typeof config === "function") {
44
+ config = config();
45
+ } else {
46
+ config = Object.assign({}, config);
47
+ }
48
+ if (!config.plugins) {
49
+ config.plugins = [];
50
+ }
51
+ return {
52
+ file,
53
+ plugins: (0, _plugins.default)(config, file),
54
+ options: (0, _options.default)(config, file)
55
+ };
56
+ })() : await (0, _postcssLoadConfig.default)();
57
+ let configPlugins = config.plugins;
58
+ let configPluginTailwindIdx = configPlugins.findIndex((plugin)=>{
59
+ if (typeof plugin === "function" && plugin.name === "tailwindcss") {
60
+ return true;
61
+ }
62
+ if (typeof plugin === "object" && plugin !== null && plugin.postcssPlugin === "tailwindcss") {
63
+ return true;
64
+ }
65
+ return false;
66
+ });
67
+ let beforePlugins = configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx);
68
+ let afterPlugins = configPluginTailwindIdx === -1 ? configPlugins : configPlugins.slice(configPluginTailwindIdx + 1);
69
+ return [
70
+ beforePlugins,
71
+ afterPlugins,
72
+ config.options
73
+ ];
74
+ }
75
+ function loadBuiltinPostcssPlugins() {
76
+ let postcss = (0, _deps.loadPostcss)();
77
+ let IMPORT_COMMENT = "__TAILWIND_RESTORE_IMPORT__: ";
78
+ return [
79
+ [
80
+ (root)=>{
81
+ root.walkAtRules("import", (rule)=>{
82
+ if (rule.params.slice(1).startsWith("tailwindcss/")) {
83
+ rule.after(postcss.comment({
84
+ text: IMPORT_COMMENT + rule.params
85
+ }));
86
+ rule.remove();
87
+ }
88
+ });
89
+ },
90
+ (0, _deps.loadPostcssImport)(),
91
+ (root)=>{
92
+ root.walkComments((rule)=>{
93
+ if (rule.text.startsWith(IMPORT_COMMENT)) {
94
+ rule.after(postcss.atRule({
95
+ name: "import",
96
+ params: rule.text.replace(IMPORT_COMMENT, "")
97
+ }));
98
+ rule.remove();
99
+ }
100
+ });
101
+ },
102
+ ],
103
+ [],
104
+ {},
105
+ ];
106
+ }
107
+ let state = {
108
+ /** @type {any} */ context: null,
109
+ /** @type {ReturnType<typeof createWatcher> | null} */ watcher: null,
110
+ /** @type {{content: string, extension: string}[]} */ changedContent: [],
111
+ configDependencies: new Set(),
112
+ contextDependencies: new Set(),
113
+ /** @type {import('../../lib/content.js').ContentPath[]} */ contentPaths: [],
114
+ refreshContentPaths () {
115
+ var ref;
116
+ this.contentPaths = (0, _contentJs.parseCandidateFiles)(this.context, (ref = this.context) === null || ref === void 0 ? void 0 : ref.tailwindConfig);
117
+ },
118
+ get config () {
119
+ return this.context.tailwindConfig;
120
+ },
121
+ get contentPatterns () {
122
+ return {
123
+ all: this.contentPaths.map((contentPath)=>contentPath.pattern),
124
+ dynamic: this.contentPaths.filter((contentPath)=>contentPath.glob !== undefined).map((contentPath)=>contentPath.pattern)
125
+ };
126
+ },
127
+ loadConfig (configPath) {
128
+ if (this.watcher && configPath) {
129
+ this.refreshConfigDependencies(configPath);
130
+ }
131
+ let config = configPath ? require(configPath) : {};
132
+ // @ts-ignore
133
+ config = (0, _resolveConfigJs.default)(config, {
134
+ content: {
135
+ files: []
136
+ }
137
+ });
138
+ return config;
139
+ },
140
+ refreshConfigDependencies (configPath) {
141
+ _shared.env.DEBUG && console.time("Module dependencies");
142
+ for (let file of this.configDependencies){
143
+ delete require.cache[require.resolve(file)];
144
+ }
145
+ if (configPath) {
146
+ let deps = (0, _getModuleDependenciesJs.default)(configPath).map(({ file })=>file);
147
+ for (let dependency of deps){
148
+ this.configDependencies.add(dependency);
149
+ }
150
+ }
151
+ _shared.env.DEBUG && console.timeEnd("Module dependencies");
152
+ },
153
+ readContentPaths () {
154
+ let content = [];
155
+ // Resolve globs from the content config
156
+ // TODO: When we make the postcss plugin async-capable this can become async
157
+ let files = _fastGlob.default.sync(this.contentPatterns.all);
158
+ for (let file of files){
159
+ content.push({
160
+ content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
161
+ extension: _path.default.extname(file).slice(1)
162
+ });
163
+ }
164
+ // Resolve raw content in the tailwind config
165
+ let rawContent = this.config.content.files.filter((file)=>{
166
+ return file !== null && typeof file === "object";
167
+ });
168
+ for (let { raw: content1 , extension ="html" } of rawContent){
169
+ content1.push({
170
+ content: content1,
171
+ extension
172
+ });
173
+ }
174
+ return content;
175
+ },
176
+ getContext ({ createContext , cliConfigPath , root , result }) {
177
+ if (this.context) {
178
+ this.context.changedContent = this.changedContent.splice(0);
179
+ return this.context;
180
+ }
181
+ _shared.env.DEBUG && console.time("Searching for config");
182
+ var ref;
183
+ let configPath = (ref = (0, _findAtConfigPathJs.findAtConfigPath)(root, result)) !== null && ref !== void 0 ? ref : cliConfigPath;
184
+ _shared.env.DEBUG && console.timeEnd("Searching for config");
185
+ _shared.env.DEBUG && console.time("Loading config");
186
+ let config = this.loadConfig(configPath);
187
+ _shared.env.DEBUG && console.timeEnd("Loading config");
188
+ _shared.env.DEBUG && console.time("Creating context");
189
+ this.context = createContext(config, []);
190
+ Object.assign(this.context, {
191
+ userConfigPath: configPath
192
+ });
193
+ _shared.env.DEBUG && console.timeEnd("Creating context");
194
+ _shared.env.DEBUG && console.time("Resolving content paths");
195
+ this.refreshContentPaths();
196
+ _shared.env.DEBUG && console.timeEnd("Resolving content paths");
197
+ if (this.watcher) {
198
+ _shared.env.DEBUG && console.time("Watch new files");
199
+ this.watcher.refreshWatchedFiles();
200
+ _shared.env.DEBUG && console.timeEnd("Watch new files");
201
+ }
202
+ _shared.env.DEBUG && console.time("Reading content files");
203
+ for (let file of this.readContentPaths()){
204
+ this.context.changedContent.push(file);
205
+ }
206
+ _shared.env.DEBUG && console.timeEnd("Reading content files");
207
+ return this.context;
208
+ }
209
+ };
210
+ async function createProcessor(args, cliConfigPath) {
211
+ let postcss = (0, _deps.loadPostcss)();
212
+ let input = args["--input"];
213
+ let output = args["--output"];
214
+ let includePostCss = args["--postcss"];
215
+ let customPostCssPath = typeof args["--postcss"] === "string" ? args["--postcss"] : undefined;
216
+ let [beforePlugins, afterPlugins, postcssOptions] = includePostCss ? await loadPostCssPlugins(customPostCssPath) : loadBuiltinPostcssPlugins();
217
+ let tailwindPlugin = ()=>{
218
+ return {
219
+ postcssPlugin: "tailwindcss",
220
+ Once (root, { result }) {
221
+ _shared.env.DEBUG && console.time("Compiling CSS");
222
+ (0, _processTailwindFeatures.default)(({ createContext })=>{
223
+ console.error();
224
+ console.error("Rebuilding...");
225
+ return ()=>{
226
+ return state.getContext({
227
+ createContext,
228
+ cliConfigPath,
229
+ root,
230
+ result
231
+ });
232
+ };
233
+ })(root, result);
234
+ _shared.env.DEBUG && console.timeEnd("Compiling CSS");
235
+ }
236
+ };
237
+ };
238
+ tailwindPlugin.postcss = true;
239
+ let plugins = [
240
+ ...beforePlugins,
241
+ tailwindPlugin,
242
+ !args["--minify"] && _utils.formatNodes,
243
+ ...afterPlugins,
244
+ !args["--no-autoprefixer"] && (0, _deps.loadAutoprefixer)(),
245
+ args["--minify"] && (0, _deps.loadCssNano)(),
246
+ ].filter(Boolean);
247
+ /** @type {import('postcss').Processor} */ // @ts-ignore
248
+ let processor = postcss(plugins);
249
+ async function readInput() {
250
+ // Piping in data, let's drain the stdin
251
+ if (input === "-") {
252
+ return (0, _utils.drainStdin)();
253
+ }
254
+ // Input file has been provided
255
+ if (input) {
256
+ return _fs.default.promises.readFile(_path.default.resolve(input), "utf8");
257
+ }
258
+ // No input file provided, fallback to default atrules
259
+ return "@tailwind base; @tailwind components; @tailwind utilities";
260
+ }
261
+ async function build() {
262
+ let start = process.hrtime.bigint();
263
+ return readInput().then((css)=>processor.process(css, {
264
+ ...postcssOptions,
265
+ from: input,
266
+ to: output
267
+ })).then((result)=>{
268
+ if (!output) {
269
+ process.stdout.write(result.css);
270
+ return;
271
+ }
272
+ return Promise.all([
273
+ (0, _utils.outputFile)(output, result.css),
274
+ result.map && (0, _utils.outputFile)(output + ".map", result.map.toString()),
275
+ ]);
276
+ }).then(()=>{
277
+ let end = process.hrtime.bigint();
278
+ console.error();
279
+ console.error("Done in", (end - start) / BigInt(1e6) + "ms.");
280
+ });
281
+ }
282
+ /**
283
+ * @param {{file: string, content(): Promise<string>, extension: string}[]} changes
284
+ */ async function parseChanges(changes) {
285
+ return Promise.all(changes.map(async (change)=>({
286
+ content: await change.content(),
287
+ extension: change.extension
288
+ })));
289
+ }
290
+ if (input !== undefined && input !== "-") {
291
+ state.contextDependencies.add(_path.default.resolve(input));
292
+ }
293
+ return {
294
+ build,
295
+ watch: async ()=>{
296
+ state.watcher = (0, _watchingJs.createWatcher)(args, {
297
+ state,
298
+ /**
299
+ * @param {{file: string, content(): Promise<string>, extension: string}[]} changes
300
+ */ async rebuild (changes) {
301
+ let needsNewContext = changes.some((change)=>{
302
+ return state.configDependencies.has(change.file) || state.contextDependencies.has(change.file);
303
+ });
304
+ if (needsNewContext) {
305
+ state.context = null;
306
+ } else {
307
+ for (let change of (await parseChanges(changes))){
308
+ state.changedContent.push(change);
309
+ }
310
+ }
311
+ return build();
312
+ }
313
+ });
314
+ await build();
315
+ }
316
+ };
317
+ }
@@ -0,0 +1,78 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ indentRecursive: ()=>indentRecursive,
14
+ formatNodes: ()=>formatNodes,
15
+ readFileWithRetries: ()=>readFileWithRetries,
16
+ drainStdin: ()=>drainStdin,
17
+ outputFile: ()=>outputFile
18
+ });
19
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
20
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
21
+ function _interopRequireDefault(obj) {
22
+ return obj && obj.__esModule ? obj : {
23
+ default: obj
24
+ };
25
+ }
26
+ function indentRecursive(node, indent = 0) {
27
+ node.each && node.each((child, i)=>{
28
+ if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes("\n")) {
29
+ child.raws.before = `\n${node.type !== "rule" && i > 0 ? "\n" : ""}${" ".repeat(indent)}`;
30
+ }
31
+ child.raws.after = `\n${" ".repeat(indent)}`;
32
+ indentRecursive(child, indent + 1);
33
+ });
34
+ }
35
+ function formatNodes(root) {
36
+ indentRecursive(root);
37
+ if (root.first) {
38
+ root.first.raws.before = "";
39
+ }
40
+ }
41
+ async function readFileWithRetries(path, tries = 5) {
42
+ for(let n = 0; n <= tries; n++){
43
+ try {
44
+ return await _fs.default.promises.readFile(path, "utf8");
45
+ } catch (err) {
46
+ if (n !== tries) {
47
+ if (err.code === "ENOENT" || err.code === "EBUSY") {
48
+ await new Promise((resolve)=>setTimeout(resolve, 10));
49
+ continue;
50
+ }
51
+ }
52
+ throw err;
53
+ }
54
+ }
55
+ }
56
+ function drainStdin() {
57
+ return new Promise((resolve, reject)=>{
58
+ let result = "";
59
+ process.stdin.on("data", (chunk)=>{
60
+ result += chunk;
61
+ });
62
+ process.stdin.on("end", ()=>resolve(result));
63
+ process.stdin.on("error", (err)=>reject(err));
64
+ });
65
+ }
66
+ async function outputFile(file, newContents) {
67
+ try {
68
+ let currentContents = await _fs.default.promises.readFile(file, "utf8");
69
+ if (currentContents === newContents) {
70
+ return; // Skip writing the file
71
+ }
72
+ } catch {}
73
+ // Write the file
74
+ await _fs.default.promises.mkdir(_path.default.dirname(file), {
75
+ recursive: true
76
+ });
77
+ await _fs.default.promises.writeFile(file, newContents, "utf8");
78
+ }
@@ -0,0 +1,113 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "createWatcher", {
7
+ enumerable: true,
8
+ get: ()=>createWatcher
9
+ });
10
+ const _chokidar = /*#__PURE__*/ _interopRequireDefault(require("chokidar"));
11
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
12
+ const _micromatch = /*#__PURE__*/ _interopRequireDefault(require("micromatch"));
13
+ const _normalizePath = /*#__PURE__*/ _interopRequireDefault(require("normalize-path"));
14
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
15
+ const _utilsJs = require("./utils.js");
16
+ function _interopRequireDefault(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
21
+ function createWatcher(args, { state , rebuild }) {
22
+ let shouldPoll = args["--poll"];
23
+ let shouldCoalesceWriteEvents = shouldPoll || process.platform === "win32";
24
+ // Polling interval in milliseconds
25
+ // Used only when polling or coalescing add/change events on Windows
26
+ let pollInterval = 10;
27
+ let watcher = _chokidar.default.watch([], {
28
+ // Force checking for atomic writes in all situations
29
+ // This causes chokidar to wait up to 100ms for a file to re-added after it's been unlinked
30
+ // This only works when watching directories though
31
+ atomic: true,
32
+ usePolling: shouldPoll,
33
+ interval: shouldPoll ? pollInterval : undefined,
34
+ ignoreInitial: true,
35
+ awaitWriteFinish: shouldCoalesceWriteEvents ? {
36
+ stabilityThreshold: 50,
37
+ pollInterval: pollInterval
38
+ } : false
39
+ });
40
+ let chain = Promise.resolve();
41
+ let pendingRebuilds = new Set();
42
+ let changedContent = [];
43
+ /**
44
+ *
45
+ * @param {*} file
46
+ * @param {(() => Promise<string>) | null} content
47
+ */ function recordChangedFile(file, content = null) {
48
+ file = _path.default.resolve(file);
49
+ content = content !== null && content !== void 0 ? content : async ()=>await _fs.default.promises.readFile(file, "utf8");
50
+ changedContent.push({
51
+ file,
52
+ content,
53
+ extension: _path.default.extname(file).slice(1)
54
+ });
55
+ chain = chain.then(()=>rebuild(changedContent));
56
+ return chain;
57
+ }
58
+ watcher.on("change", (file)=>recordChangedFile(file));
59
+ watcher.on("add", (file)=>recordChangedFile(file));
60
+ // Restore watching any files that are "removed"
61
+ // This can happen when a file is pseudo-atomically replaced (a copy is created, overwritten, the old one is unlinked, and the new one is renamed)
62
+ // TODO: An an optimization we should allow removal when the config changes
63
+ watcher.on("unlink", (file)=>{
64
+ file = (0, _normalizePath.default)(file);
65
+ // Only re-add the file if it's not covered by a dynamic pattern
66
+ if (!_micromatch.default.some([
67
+ file
68
+ ], state.contentPatterns.dynamic)) {
69
+ watcher.add(file);
70
+ }
71
+ });
72
+ // Some applications such as Visual Studio (but not VS Code)
73
+ // will only fire a rename event for atomic writes and not a change event
74
+ // This is very likely a chokidar bug but it's one we need to work around
75
+ // We treat this as a change event and rebuild the CSS
76
+ watcher.on("raw", (evt, filePath, meta)=>{
77
+ if (evt !== "rename") {
78
+ return;
79
+ }
80
+ let watchedPath = meta.watchedPath;
81
+ // Watched path might be the file itself
82
+ // Or the directory it is in
83
+ filePath = watchedPath.endsWith(filePath) ? watchedPath : _path.default.join(watchedPath, filePath);
84
+ // Skip this event since the files it is for does not match any of the registered content globs
85
+ if (!_micromatch.default.some([
86
+ filePath
87
+ ], state.contentPatterns.all)) {
88
+ return;
89
+ }
90
+ // Skip since we've already queued a rebuild for this file that hasn't happened yet
91
+ if (pendingRebuilds.has(filePath)) {
92
+ return;
93
+ }
94
+ pendingRebuilds.add(filePath);
95
+ chain = chain.then(async ()=>{
96
+ let content;
97
+ try {
98
+ content = await (0, _utilsJs.readFileWithRetries)(_path.default.resolve(filePath));
99
+ } finally{
100
+ pendingRebuilds.delete(filePath);
101
+ }
102
+ return recordChangedFile(filePath, ()=>content);
103
+ });
104
+ });
105
+ return {
106
+ fswatcher: watcher,
107
+ refreshWatchedFiles () {
108
+ watcher.add(Array.from(state.contextDependencies));
109
+ watcher.add(Array.from(state.configDependencies));
110
+ watcher.add(state.contentPatterns.all);
111
+ }
112
+ };
113
+ }