@master/css-project 2.0.0-rc.70
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/README.md +135 -0
- package/dist/entries.d.ts +12 -0
- package/dist/entries.mjs +210 -0
- package/dist/manifest-sync.d.ts +10 -0
- package/dist/manifest-sync.mjs +42 -0
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.mjs +42 -0
- package/dist/options.d.ts +12 -0
- package/dist/options.mjs +1 -0
- package/package.json +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<br>
|
|
2
|
+
<div align="center">
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://css.master.co">
|
|
6
|
+
<picture>
|
|
7
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/33840671/201701649-3bb7d698-abec-4d5f-ac30-ccc4d7bafcd4.svg">
|
|
8
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg">
|
|
9
|
+
<img alt="Master CSS" src="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg" width="100%">
|
|
10
|
+
</picture>
|
|
11
|
+
</a>
|
|
12
|
+
</p>
|
|
13
|
+
<p align="center">Utilities for loading and serializing Master CSS manifest CSS resources</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a aria-label="GitHub release (latest by date including pre-releases)" href="https://github.com/master-co/css/releases">
|
|
17
|
+
<picture>
|
|
18
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=212022&label=&style=for-the-badge&logo=github&logoColor=fff">
|
|
19
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github&logoColor=%23000">
|
|
20
|
+
<img alt="NPM Version" src="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github">
|
|
21
|
+
</picture>
|
|
22
|
+
</a>
|
|
23
|
+
<a aria-label="NPM Package" href="https://www.npmjs.com/package/@master/css-project">
|
|
24
|
+
<picture>
|
|
25
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/@master/css-project?color=212022&label=%20&logo=npm&style=for-the-badge">
|
|
26
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/dm/@master/css-project?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
27
|
+
<img alt="NPM package ( download / month )" src="https://img.shields.io/npm/dm/@master/css-project?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
28
|
+
</picture>
|
|
29
|
+
</a>
|
|
30
|
+
<a aria-label="Discord Community" href="https://discord.gg/sZNKpAAAw6">
|
|
31
|
+
<picture>
|
|
32
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/discord/917780624314613760?color=212022&label=%20&logo=discord&style=for-the-badge">
|
|
33
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
34
|
+
<img alt="Discord online" src="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
35
|
+
</picture>
|
|
36
|
+
</a>
|
|
37
|
+
<a aria-label="Follow @mastercorg" href="https://twitter.com/mastercorg">
|
|
38
|
+
<picture>
|
|
39
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=212022&logo=twitter&style=for-the-badge">
|
|
40
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
41
|
+
<img alt="Follow @mastercorg" src="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
42
|
+
</picture>
|
|
43
|
+
</a>
|
|
44
|
+
<a aria-label="Github Actions" href="https://github.com/master-co/css/actions/workflows/ci-release.yml">
|
|
45
|
+
<picture>
|
|
46
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge">
|
|
47
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
48
|
+
<img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
49
|
+
</picture>
|
|
50
|
+
</a>
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install @master/css-project
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`@master/css-project` is the shared project manifest boundary for CLI commands, ESLint, language tooling, and build integrations such as Vite, Next.js, Webpack, and Nuxt.
|
|
62
|
+
|
|
63
|
+
It discovers project CSS entries and Master CSS workspace roots, then delegates CSS parsing, import graph resolution, and manifest compilation to `@master/css-compiler`. JavaScript and TypeScript config files are intentionally unsupported.
|
|
64
|
+
|
|
65
|
+
Project entry discovery only treats CSS files with top-level `@master;` or `@import '@master/css'` as entries. Imported `@settings`, `@theme`, and `@custom-variant` directives participate in the entry graph, but they are not independent project entries.
|
|
66
|
+
|
|
67
|
+
## Load project manifest
|
|
68
|
+
|
|
69
|
+
Use `loadProjectManifest()` when a tool should load the canonical project-level manifest for a directory.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { loadProjectManifest, loadProjectManifestJSON } from '@master/css-project/manifest'
|
|
73
|
+
|
|
74
|
+
const result = await loadProjectManifest('/project')
|
|
75
|
+
const jsonResult = await loadProjectManifestJSON('/project')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`loadProjectManifest()` discovers project CSS entries unless explicit `entries` are passed. It returns the compiled manifest and dependency list. `loadProjectManifestJSON()` returns JSON source for virtual JSON modules and loader output.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { loadProjectManifestSync, loadProjectManifestJSONSync } from '@master/css-project/manifest-sync'
|
|
82
|
+
|
|
83
|
+
const result = loadProjectManifestSync('/project')
|
|
84
|
+
const jsonResult = loadProjectManifestJSONSync('/project')
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Load explicit CSS resources
|
|
88
|
+
|
|
89
|
+
Use `loadManifest()` when the CSS resource path is already known and should be compiled directly.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { loadManifest, loadManifestJSON } from '@master/css-project/manifest'
|
|
93
|
+
|
|
94
|
+
const result = await loadManifest('/project/src/index.css')
|
|
95
|
+
const jsonResult = await loadManifestJSON('/project/src/index.css')
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`loadManifest()` and `loadManifestJSON()` only accept CSS resources. They do not search the workspace and do not load JavaScript or TypeScript config files.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { loadManifestSync, loadManifestJSONSync } from '@master/css-project/manifest-sync'
|
|
102
|
+
|
|
103
|
+
const result = loadManifestSync('/project/src/index.css')
|
|
104
|
+
const jsonResult = loadManifestJSONSync('/project/src/index.css')
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Discover entries and workspaces
|
|
108
|
+
|
|
109
|
+
Use `@master/css-project/entries` when tooling needs the same project entry and workspace discovery rules without loading a manifest.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import {
|
|
113
|
+
findCSSManifestEntryFiles,
|
|
114
|
+
findMasterCSSWorkspaceDirectories,
|
|
115
|
+
hasMasterCSSManifestEntrypoint,
|
|
116
|
+
} from '@master/css-project/entries'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`findCSSManifestEntryFiles(projectDir)` searches CSS files for entry markers. `findMasterCSSWorkspaceDirectories(rootDir)` creates workspace roots from discovered CSS entries and `package.json` files that declare Master CSS package dependencies.
|
|
120
|
+
|
|
121
|
+
## Manifest modules
|
|
122
|
+
|
|
123
|
+
The module utilities define the manifest import contract used by official integrations. They live in `@master/css-integration`; `@master/css-project` owns loading and discovery.
|
|
124
|
+
|
|
125
|
+
| API | Purpose |
|
|
126
|
+
| --- | --- |
|
|
127
|
+
| `VIRTUAL_MANIFEST_ID` | Default manifest JS facade module id, `virtual:master-css-manifest`. |
|
|
128
|
+
| `VIRTUAL_EMITTED_GLOBALS_ID` | Default emittedGlobals module id, `virtual:master-css-emitted-globals`. |
|
|
129
|
+
| `MASTER_CSS_MANIFEST_QUERY` | Query suffix, `?master-css-manifest`, used to compile one explicit CSS resource. |
|
|
130
|
+
| `toManifestJSON(manifest)` | Serializes a manifest object into normalized JSON source. |
|
|
131
|
+
| `toEmittedGlobalsModule(emittedGlobals)` | Serializes emittedGlobals variable and animation counts into an ESM default export. |
|
|
132
|
+
| `toVirtualDefaultManifestModulePath(context)` | Creates the virtual path for the default manifest module. |
|
|
133
|
+
| `toVirtualCSSManifestModulePath(context, file)` | Creates a virtual path for one explicit queried CSS resource. |
|
|
134
|
+
|
|
135
|
+
Use `virtual:master-css-manifest` and `virtual:master-css-emitted-globals` when application code should receive an integration's canonical project-level runtime inputs. Use `./index.css?master-css-manifest` only when the code intentionally compiles one explicit CSS resource through the active integration.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { resolveMasterCSSPackageEntryFile } from '@master/css-compiler';
|
|
2
|
+
import { createMasterCSSManifestEntryPattern, isMasterCSSModuleId, normalizeMasterCSSModuleIds } from '@master/css-lexer';
|
|
3
|
+
export declare function cleanCSSManifestRequest(id: string): string;
|
|
4
|
+
export declare function isCSSManifestRequest(id: string): boolean;
|
|
5
|
+
export { createMasterCSSManifestEntryPattern, isMasterCSSModuleId, normalizeMasterCSSModuleIds, resolveMasterCSSPackageEntryFile };
|
|
6
|
+
export declare function hasMasterCSSManifestEntrypoint(source: string): boolean;
|
|
7
|
+
export declare function findCSSManifestEntryFiles(projectDir?: string): Promise<string[]>;
|
|
8
|
+
export declare function findCSSManifestEntryFilesSync(projectDir?: string): string[];
|
|
9
|
+
export declare function findCSSManifestEntryFile(projectDir?: string): Promise<string>;
|
|
10
|
+
export declare function findCSSManifestEntryFileSync(projectDir?: string): string;
|
|
11
|
+
export declare function findMasterCSSWorkspaceDirectories(rootDir?: string): Promise<string[]>;
|
|
12
|
+
export declare function findMasterCSSWorkspaceDirectoriesSync(rootDir?: string): string[];
|
package/dist/entries.mjs
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { extname, resolve, join, dirname, relative, sep, isAbsolute } from 'node:path';
|
|
4
|
+
import { inspectCSS } from '@master/css-compiler';
|
|
5
|
+
export { resolveMasterCSSPackageEntryFile } from '@master/css-compiler';
|
|
6
|
+
import { hasMasterCSSManifestEntrypoint as hasMasterCSSManifestEntrypoint$1 } from '@master/css-lexer';
|
|
7
|
+
export { createMasterCSSManifestEntryPattern, isMasterCSSModuleId, normalizeMasterCSSModuleIds } from '@master/css-lexer';
|
|
8
|
+
import { stripResourceQuery } from '@master/css-integration/manifest-module';
|
|
9
|
+
|
|
10
|
+
const CSS_MANIFEST_ENTRY_IGNORED_DIRECTORIES = new Set([
|
|
11
|
+
'node_modules',
|
|
12
|
+
'dist',
|
|
13
|
+
'out',
|
|
14
|
+
'.next',
|
|
15
|
+
'.nuxt',
|
|
16
|
+
'.svelte-kit'
|
|
17
|
+
]);
|
|
18
|
+
const MASTER_CSS_PACKAGE_NAME_PATTERN = /^@master\/css(?:$|[.-])/;
|
|
19
|
+
const PACKAGE_JSON_DEPENDENCY_FIELDS = [
|
|
20
|
+
'dependencies',
|
|
21
|
+
'devDependencies',
|
|
22
|
+
'peerDependencies',
|
|
23
|
+
'optionalDependencies'
|
|
24
|
+
];
|
|
25
|
+
function cleanCSSManifestRequest(id) {
|
|
26
|
+
return stripResourceQuery(id);
|
|
27
|
+
}
|
|
28
|
+
function isCSSManifestRequest(id) {
|
|
29
|
+
return extname(cleanCSSManifestRequest(id)) === '.css';
|
|
30
|
+
}
|
|
31
|
+
function hasMasterCSSManifestEntrypoint(source) {
|
|
32
|
+
try {
|
|
33
|
+
return inspectCSS(source).hasMasterEntry;
|
|
34
|
+
} catch {
|
|
35
|
+
return hasMasterCSSManifestEntrypoint$1(source);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function collectCSSManifestEntryFiles(directory, entries) {
|
|
39
|
+
try {
|
|
40
|
+
for (const dirent of (await readdir(directory, {
|
|
41
|
+
withFileTypes: true
|
|
42
|
+
}))){
|
|
43
|
+
const file = join(directory, dirent.name);
|
|
44
|
+
if (dirent.isDirectory()) {
|
|
45
|
+
if (CSS_MANIFEST_ENTRY_IGNORED_DIRECTORIES.has(dirent.name)) continue;
|
|
46
|
+
await collectCSSManifestEntryFiles(file, entries);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!dirent.isFile() || extname(dirent.name) !== '.css') continue;
|
|
50
|
+
try {
|
|
51
|
+
if (hasMasterCSSManifestEntrypoint(await readFile(file, 'utf8'))) {
|
|
52
|
+
entries.push(file);
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
// Ignore files that disappear or become unreadable while scanning.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
// Ignore directories that disappear or are unreadable while scanning.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function collectCSSManifestEntryFilesSync(directory, entries) {
|
|
63
|
+
try {
|
|
64
|
+
for (const dirent of readdirSync(directory, {
|
|
65
|
+
withFileTypes: true
|
|
66
|
+
})){
|
|
67
|
+
const file = join(directory, dirent.name);
|
|
68
|
+
if (dirent.isDirectory()) {
|
|
69
|
+
if (CSS_MANIFEST_ENTRY_IGNORED_DIRECTORIES.has(dirent.name)) continue;
|
|
70
|
+
collectCSSManifestEntryFilesSync(file, entries);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!dirent.isFile() || extname(dirent.name) !== '.css') continue;
|
|
74
|
+
try {
|
|
75
|
+
if (hasMasterCSSManifestEntrypoint(readFileSync(file, 'utf8'))) {
|
|
76
|
+
entries.push(file);
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
// Ignore files that disappear or become unreadable while scanning.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
// Ignore directories that disappear or are unreadable while scanning.
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function findCSSManifestEntryFiles(projectDir = process.cwd()) {
|
|
87
|
+
const entries = [];
|
|
88
|
+
await collectCSSManifestEntryFiles(resolve(projectDir), entries);
|
|
89
|
+
return entries.sort();
|
|
90
|
+
}
|
|
91
|
+
function findCSSManifestEntryFilesSync(projectDir = process.cwd()) {
|
|
92
|
+
const entries = [];
|
|
93
|
+
collectCSSManifestEntryFilesSync(resolve(projectDir), entries);
|
|
94
|
+
return entries.sort();
|
|
95
|
+
}
|
|
96
|
+
async function findCSSManifestEntryFile(projectDir = process.cwd()) {
|
|
97
|
+
return (await findCSSManifestEntryFiles(projectDir))[0];
|
|
98
|
+
}
|
|
99
|
+
function findCSSManifestEntryFileSync(projectDir = process.cwd()) {
|
|
100
|
+
return findCSSManifestEntryFilesSync(projectDir)[0];
|
|
101
|
+
}
|
|
102
|
+
function isMasterCSSDependencyName(dependency) {
|
|
103
|
+
return MASTER_CSS_PACKAGE_NAME_PATTERN.test(dependency);
|
|
104
|
+
}
|
|
105
|
+
function hasMasterCSSDependency(packageJSON) {
|
|
106
|
+
return PACKAGE_JSON_DEPENDENCY_FIELDS.some((field)=>{
|
|
107
|
+
const dependencies = packageJSON[field];
|
|
108
|
+
if (!dependencies || typeof dependencies !== 'object') return false;
|
|
109
|
+
return Object.keys(dependencies).some(isMasterCSSDependencyName);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async function collectMasterCSSPackageWorkspaceDirectories(directory, directories) {
|
|
113
|
+
try {
|
|
114
|
+
for (const dirent of (await readdir(directory, {
|
|
115
|
+
withFileTypes: true
|
|
116
|
+
}))){
|
|
117
|
+
const file = join(directory, dirent.name);
|
|
118
|
+
if (dirent.isDirectory()) {
|
|
119
|
+
if (CSS_MANIFEST_ENTRY_IGNORED_DIRECTORIES.has(dirent.name)) continue;
|
|
120
|
+
await collectMasterCSSPackageWorkspaceDirectories(file, directories);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!dirent.isFile() || dirent.name !== 'package.json') continue;
|
|
124
|
+
try {
|
|
125
|
+
if (hasMasterCSSDependency(JSON.parse(await readFile(file, 'utf8')))) {
|
|
126
|
+
directories.add(dirname(file));
|
|
127
|
+
}
|
|
128
|
+
} catch {
|
|
129
|
+
// Ignore invalid or disappearing package.json files.
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
// Ignore directories that disappear or are unreadable while scanning.
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function collectMasterCSSPackageWorkspaceDirectoriesSync(directory, directories) {
|
|
137
|
+
try {
|
|
138
|
+
for (const dirent of readdirSync(directory, {
|
|
139
|
+
withFileTypes: true
|
|
140
|
+
})){
|
|
141
|
+
const file = join(directory, dirent.name);
|
|
142
|
+
if (dirent.isDirectory()) {
|
|
143
|
+
if (CSS_MANIFEST_ENTRY_IGNORED_DIRECTORIES.has(dirent.name)) continue;
|
|
144
|
+
collectMasterCSSPackageWorkspaceDirectoriesSync(file, directories);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (!dirent.isFile() || dirent.name !== 'package.json') continue;
|
|
148
|
+
try {
|
|
149
|
+
if (hasMasterCSSDependency(JSON.parse(readFileSync(file, 'utf8')))) {
|
|
150
|
+
directories.add(dirname(file));
|
|
151
|
+
}
|
|
152
|
+
} catch {
|
|
153
|
+
// Ignore invalid or disappearing package.json files.
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
// Ignore directories that disappear or are unreadable while scanning.
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function isSameOrChildPath(parentPath, childPath) {
|
|
161
|
+
const relativePath = relative(parentPath, childPath);
|
|
162
|
+
return relativePath === '' || !!relativePath && relativePath !== '..' && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath);
|
|
163
|
+
}
|
|
164
|
+
function resolveWorkspaceDirectoryForEntry(cssFile, workspaceDirectories) {
|
|
165
|
+
let closestDirectory;
|
|
166
|
+
const absoluteCSSFile = resolve(cssFile);
|
|
167
|
+
for (const workspaceDir of workspaceDirectories){
|
|
168
|
+
const absoluteWorkspaceDir = resolve(workspaceDir);
|
|
169
|
+
if (isSameOrChildPath(absoluteWorkspaceDir, absoluteCSSFile) && (!closestDirectory || absoluteWorkspaceDir.length > closestDirectory.length)) {
|
|
170
|
+
closestDirectory = absoluteWorkspaceDir;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return closestDirectory || dirname(absoluteCSSFile);
|
|
174
|
+
}
|
|
175
|
+
async function findMasterCSSWorkspaceDirectories(rootDir = process.cwd()) {
|
|
176
|
+
const root = resolve(rootDir);
|
|
177
|
+
const directories = new Set([
|
|
178
|
+
root
|
|
179
|
+
]);
|
|
180
|
+
const packageDirectories = new Set();
|
|
181
|
+
await collectMasterCSSPackageWorkspaceDirectories(root, packageDirectories);
|
|
182
|
+
for (const directory of packageDirectories){
|
|
183
|
+
directories.add(directory);
|
|
184
|
+
}
|
|
185
|
+
for (const entry of (await findCSSManifestEntryFiles(root))){
|
|
186
|
+
directories.add(resolveWorkspaceDirectoryForEntry(entry, packageDirectories));
|
|
187
|
+
}
|
|
188
|
+
return [
|
|
189
|
+
...directories
|
|
190
|
+
].sort();
|
|
191
|
+
}
|
|
192
|
+
function findMasterCSSWorkspaceDirectoriesSync(rootDir = process.cwd()) {
|
|
193
|
+
const root = resolve(rootDir);
|
|
194
|
+
const directories = new Set([
|
|
195
|
+
root
|
|
196
|
+
]);
|
|
197
|
+
const packageDirectories = new Set();
|
|
198
|
+
collectMasterCSSPackageWorkspaceDirectoriesSync(root, packageDirectories);
|
|
199
|
+
for (const directory of packageDirectories){
|
|
200
|
+
directories.add(directory);
|
|
201
|
+
}
|
|
202
|
+
for (const entry of findCSSManifestEntryFilesSync(root)){
|
|
203
|
+
directories.add(resolveWorkspaceDirectoryForEntry(entry, packageDirectories));
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
...directories
|
|
207
|
+
].sort();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { cleanCSSManifestRequest, findCSSManifestEntryFile, findCSSManifestEntryFileSync, findCSSManifestEntryFiles, findCSSManifestEntryFilesSync, findMasterCSSWorkspaceDirectories, findMasterCSSWorkspaceDirectoriesSync, hasMasterCSSManifestEntrypoint, isCSSManifestRequest };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { compileCSSManifestJSON } from '@master/css-compiler';
|
|
2
|
+
import { type LoadManifestOptions, type LoadManifestResult, type LoadProjectManifestOptions, type LoadProjectManifestResult } from './options';
|
|
3
|
+
export type { LoadManifestOptions, LoadManifestResult, LoadProjectManifestOptions, LoadProjectManifestResult } from './options';
|
|
4
|
+
export type ManifestJSONResult = ReturnType<typeof compileCSSManifestJSON>;
|
|
5
|
+
export declare function loadManifestSync(path: string, options?: LoadManifestOptions): LoadManifestResult;
|
|
6
|
+
export declare function loadManifestJSONSync(path: string, options?: LoadManifestOptions): ManifestJSONResult;
|
|
7
|
+
export declare function loadProjectManifestSync(projectDir?: string, options?: LoadProjectManifestOptions): LoadProjectManifestResult;
|
|
8
|
+
export declare function loadProjectManifestJSONSync(projectDir?: string, options?: LoadProjectManifestOptions): import("@master/css-compiler").CompileProjectManifestResult & {
|
|
9
|
+
json: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { extname } from 'node:path';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { compileCSSManifestJSON, compileCSSManifestFile, compileProjectManifestJSON, compileProjectManifest } from '@master/css-compiler';
|
|
4
|
+
import { stripResourceQuery } from '@master/css-integration/manifest-module';
|
|
5
|
+
import { findCSSManifestEntryFilesSync } from './entries.mjs';
|
|
6
|
+
|
|
7
|
+
const require$1 = createRequire(import.meta.url);
|
|
8
|
+
const defaultManifest = require$1('@master/css-preset/default-manifest.json');
|
|
9
|
+
function withDefaultManifest(options) {
|
|
10
|
+
return {
|
|
11
|
+
...options,
|
|
12
|
+
baseManifest: options.baseManifest ?? defaultManifest
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function loadManifestSync(path, options = {}) {
|
|
16
|
+
if (extname(stripResourceQuery(path)) === '.css') {
|
|
17
|
+
return compileCSSManifestFile(stripResourceQuery(path), withDefaultManifest(options));
|
|
18
|
+
}
|
|
19
|
+
throw new TypeError('Master CSS manifests can only be loaded from CSS files.');
|
|
20
|
+
}
|
|
21
|
+
function loadManifestJSONSync(path, options = {}) {
|
|
22
|
+
if (extname(stripResourceQuery(path)) === '.css') {
|
|
23
|
+
return compileCSSManifestJSON(stripResourceQuery(path), withDefaultManifest(options));
|
|
24
|
+
}
|
|
25
|
+
throw new TypeError('Master CSS manifest JSON can only be loaded from CSS files.');
|
|
26
|
+
}
|
|
27
|
+
function loadProjectManifestSync(projectDir = process.cwd(), options = {}) {
|
|
28
|
+
const entries = options.entries ?? findCSSManifestEntryFilesSync(projectDir);
|
|
29
|
+
return compileProjectManifest(entries, {
|
|
30
|
+
...withDefaultManifest(options),
|
|
31
|
+
root: projectDir
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function loadProjectManifestJSONSync(projectDir = process.cwd(), options = {}) {
|
|
35
|
+
const entries = options.entries ?? findCSSManifestEntryFilesSync(projectDir);
|
|
36
|
+
return compileProjectManifestJSON(entries, {
|
|
37
|
+
...withDefaultManifest(options),
|
|
38
|
+
root: projectDir
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { loadManifestJSONSync, loadManifestSync, loadProjectManifestJSONSync, loadProjectManifestSync };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { compileCSSManifestJSON } from '@master/css-compiler';
|
|
2
|
+
import { type LoadManifestOptions, type LoadManifestResult, type LoadProjectManifestOptions, type LoadProjectManifestResult } from './options';
|
|
3
|
+
export type { LoadManifestOptions, LoadManifestResult, LoadProjectManifestOptions, LoadProjectManifestResult } from './options';
|
|
4
|
+
export type ManifestJSONResult = ReturnType<typeof compileCSSManifestJSON>;
|
|
5
|
+
export declare function loadManifest(path: string, options?: LoadManifestOptions): Promise<LoadManifestResult>;
|
|
6
|
+
export declare function loadManifestJSON(path: string, options?: LoadManifestOptions): Promise<ManifestJSONResult>;
|
|
7
|
+
export declare function loadProjectManifest(projectDir?: string, options?: LoadProjectManifestOptions): Promise<LoadProjectManifestResult>;
|
|
8
|
+
export declare function loadProjectManifestJSON(projectDir?: string, options?: LoadProjectManifestOptions): Promise<import("@master/css-compiler").CompileProjectManifestResult & {
|
|
9
|
+
json: string;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { extname } from 'node:path';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { compileCSSManifestFile, compileCSSManifestJSON, compileProjectManifest, compileProjectManifestJSON } from '@master/css-compiler';
|
|
4
|
+
import { stripResourceQuery } from '@master/css-integration/manifest-module';
|
|
5
|
+
import { findCSSManifestEntryFiles } from './entries.mjs';
|
|
6
|
+
|
|
7
|
+
const require$1 = createRequire(import.meta.url);
|
|
8
|
+
const defaultManifest = require$1('@master/css-preset/default-manifest.json');
|
|
9
|
+
function withDefaultManifest(options) {
|
|
10
|
+
return {
|
|
11
|
+
...options,
|
|
12
|
+
baseManifest: options.baseManifest ?? defaultManifest
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async function loadManifest(path, options = {}) {
|
|
16
|
+
if (extname(stripResourceQuery(path)) === '.css') {
|
|
17
|
+
return compileCSSManifestFile(stripResourceQuery(path), withDefaultManifest(options));
|
|
18
|
+
}
|
|
19
|
+
throw new TypeError('Master CSS manifests can only be loaded from CSS files.');
|
|
20
|
+
}
|
|
21
|
+
async function loadManifestJSON(path, options = {}) {
|
|
22
|
+
if (extname(stripResourceQuery(path)) === '.css') {
|
|
23
|
+
return compileCSSManifestJSON(stripResourceQuery(path), withDefaultManifest(options));
|
|
24
|
+
}
|
|
25
|
+
throw new TypeError('Master CSS manifest JSON can only be loaded from CSS files.');
|
|
26
|
+
}
|
|
27
|
+
async function loadProjectManifest(projectDir = process.cwd(), options = {}) {
|
|
28
|
+
const entries = options.entries ?? await findCSSManifestEntryFiles(projectDir);
|
|
29
|
+
return compileProjectManifest(entries, {
|
|
30
|
+
...withDefaultManifest(options),
|
|
31
|
+
root: projectDir
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function loadProjectManifestJSON(projectDir = process.cwd(), options = {}) {
|
|
35
|
+
const entries = options.entries ?? await findCSSManifestEntryFiles(projectDir);
|
|
36
|
+
return compileProjectManifestJSON(entries, {
|
|
37
|
+
...withDefaultManifest(options),
|
|
38
|
+
root: projectDir
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { loadManifest, loadManifestJSON, loadProjectManifest, loadProjectManifestJSON };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CompileCSSManifestResult, CompileProjectManifestResult } from '@master/css-compiler';
|
|
2
|
+
import type { MasterCSSManifest } from '@master/css-schema/manifest';
|
|
3
|
+
export interface LoadManifestOptions {
|
|
4
|
+
baseManifest?: MasterCSSManifest;
|
|
5
|
+
classes?: string[];
|
|
6
|
+
onWarning?: (warning: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export type LoadManifestResult = CompileCSSManifestResult;
|
|
9
|
+
export interface LoadProjectManifestOptions extends LoadManifestOptions {
|
|
10
|
+
entries?: string[];
|
|
11
|
+
}
|
|
12
|
+
export type LoadProjectManifestResult = CompileProjectManifestResult;
|
package/dist/options.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"@master/css-project","type":"module","scripts":{"build":"techor build \"src/**/*.ts\" --formats esm","dev":"pnpm build --watch","lint":"eslint","type-check":"tsc --noEmit","test":"vitest"},"license":"MIT","description":"Master CSS project entry discovery and manifest loading utilities.","author":"Aoyue Design LLC.","funding":"https://rc.css.master.co/sponsor","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/project"},"keywords":["project","manifest","css","mastercss"],"sideEffects":false,"types":"./dist/manifest.d.ts","exports":{"./manifest":{"types":"./dist/manifest.d.ts","import":"./dist/manifest.mjs","default":"./dist/manifest.mjs"},"./manifest-sync":{"types":"./dist/manifest-sync.d.ts","import":"./dist/manifest-sync.mjs","default":"./dist/manifest-sync.mjs"},"./entries":{"types":"./dist/entries.d.ts","import":"./dist/entries.mjs","default":"./dist/entries.mjs"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/css-compiler":"^2.0.0-rc.70","@master/css-integration":"^2.0.0-rc.70","@master/css-lexer":"^2.0.0-rc.70","@master/css-preset":"^2.0.0-rc.70","@master/css-schema":"^2.0.0-rc.70"},"version":"2.0.0-rc.70"}
|