vuetify-nuxt-module 1.0.0-alpha.6 → 1.0.0-beta.2
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 +1 -1
- package/README.md +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +90 -61
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023-PRESENT
|
|
3
|
+
Copyright (c) 2023-PRESENT Vuetify, LLC <https://github.com/vuetifyjs>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
> Requires Vite, will not work with Webpack
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
npx
|
|
55
|
+
npx nuxt module add vuetify-nuxt-module
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
[](https://stackblitz.com/github/userquin/vuetify-nuxt-module)
|
|
@@ -92,4 +92,4 @@ The virtual modules can be found in [configuration.d.ts](https://github.com/vuet
|
|
|
92
92
|
|
|
93
93
|
## 📄 License
|
|
94
94
|
|
|
95
|
-
[MIT](https://github.com/vuetifyjs/nuxt-module/blob/main/LICENSE) License © 2023-PRESENT [
|
|
95
|
+
[MIT](https://github.com/vuetifyjs/nuxt-module/blob/main/LICENSE) License © 2023-PRESENT [Vuetify, LLC](https://github.com/vuetifyjs)
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { addPluginTemplate,
|
|
1
|
+
import { addPluginTemplate, resolvePath, addTemplate, extendWebpackConfig, isNuxtMajorVersion, addImports, addPlugin, addVitePlugin, useLogger, defineNuxtModule, getNuxtVersion, hasNuxtModule, createResolver } from '@nuxt/kit';
|
|
2
2
|
import { isPackageExists, getPackageInfo } from 'local-pkg';
|
|
3
3
|
import semver from 'semver';
|
|
4
4
|
import { createFilter, version as version$1 } from 'vite';
|
|
5
|
-
import fs, { existsSync, statSync, readFileSync, readdirSync, rmSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
6
|
-
import { isAbsolute, resolve, relative } from 'pathe';
|
|
7
5
|
import defu from 'defu';
|
|
8
6
|
import { transformAssetUrls } from 'vite-plugin-vuetify';
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import fs, { existsSync, readdirSync, rmSync, statSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { isAbsolute, resolve, join, relative, dirname } from 'pathe';
|
|
9
10
|
import { pathToFileURL } from 'node:url';
|
|
10
|
-
import { generateImports,
|
|
11
|
+
import { generateImports, isObject, resolveVuetifyBase, normalizePath } from '@vuetify/loader-shared';
|
|
11
12
|
import destr from 'destr';
|
|
12
13
|
import { parseQuery, parseURL } from 'ufo';
|
|
13
14
|
import fsp, { readFile } from 'node:fs/promises';
|
|
14
15
|
import path from 'upath';
|
|
15
|
-
import { resolve as resolve$1, dirname, join, relative as relative$1 } from 'node:path';
|
|
16
16
|
import { debounce } from 'perfect-debounce';
|
|
17
17
|
import process from 'node:process';
|
|
18
18
|
import { createConfigLoader } from 'unconfig';
|
|
19
|
-
import { createHash } from 'node:crypto';
|
|
20
19
|
|
|
21
|
-
const version = "1.0.0-
|
|
20
|
+
const version = "1.0.0-beta.2";
|
|
22
21
|
|
|
23
22
|
const VIRTUAL_VUETIFY_CONFIGURATION = "virtual:vuetify-configuration";
|
|
24
23
|
const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `\0${VIRTUAL_VUETIFY_CONFIGURATION}`;
|
|
@@ -128,6 +127,64 @@ function normalizeTransformAssetUrlsAttrs(attrs) {
|
|
|
128
127
|
return [...result];
|
|
129
128
|
}
|
|
130
129
|
|
|
130
|
+
function resolveVuetifyConfigFile(configFile, nuxt) {
|
|
131
|
+
if (typeof configFile === "string" && !isAbsolute(configFile)) {
|
|
132
|
+
for (const layer of nuxt.options._layers) {
|
|
133
|
+
const resolved = resolve(layer.config.srcDir, configFile);
|
|
134
|
+
if (existsSync(resolved)) {
|
|
135
|
+
return resolved;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return configFile;
|
|
140
|
+
}
|
|
141
|
+
function createStylesCacheHash(vuetifyVersion, viteVersion, configContent, configFile) {
|
|
142
|
+
return createHash("sha256").update(vuetifyVersion).update(viteVersion).update(configContent).update(configFile).digest("hex").slice(0, 8);
|
|
143
|
+
}
|
|
144
|
+
function resolveStylesCachePaths(rootDir, hash) {
|
|
145
|
+
const stylesDir = resolve(rootDir, "node_modules/.cache/vuetify-nuxt-module/styles");
|
|
146
|
+
const cacheDir = join(stylesDir, hash);
|
|
147
|
+
return {
|
|
148
|
+
stylesDir,
|
|
149
|
+
cacheDir
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function cleanupOldStylesCaches(stylesDir, currentHash) {
|
|
153
|
+
if (!existsSync(stylesDir)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const dirents = readdirSync(stylesDir, { withFileTypes: true });
|
|
157
|
+
for (const dirent of dirents) {
|
|
158
|
+
if (dirent.isDirectory() && dirent.name !== currentHash) {
|
|
159
|
+
rmSync(join(stylesDir, dirent.name), { recursive: true, force: true });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function collectVuetifyCssFiles(vuetifyBase) {
|
|
164
|
+
const files = [];
|
|
165
|
+
findCssFiles(join(vuetifyBase, "lib/components"), files);
|
|
166
|
+
findCssFiles(join(vuetifyBase, "lib/styles"), files);
|
|
167
|
+
return files;
|
|
168
|
+
}
|
|
169
|
+
function findCssFiles(dir, fileList = []) {
|
|
170
|
+
if (!existsSync(dir)) {
|
|
171
|
+
return fileList;
|
|
172
|
+
}
|
|
173
|
+
const files = readdirSync(dir);
|
|
174
|
+
for (const file of files) {
|
|
175
|
+
const filePath = join(dir, file);
|
|
176
|
+
const stat = statSync(filePath);
|
|
177
|
+
if (stat.isDirectory()) {
|
|
178
|
+
findCssFiles(filePath, fileList);
|
|
179
|
+
} else {
|
|
180
|
+
if (file.endsWith(".css")) {
|
|
181
|
+
fileList.push(filePath);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return fileList;
|
|
186
|
+
}
|
|
187
|
+
|
|
131
188
|
function addVuetifyNuxtPlugins(nuxt, ctx) {
|
|
132
189
|
addVuetifyNuxtPlugin(nuxt, ctx, "client");
|
|
133
190
|
addVuetifyNuxtPlugin(nuxt, ctx, "server");
|
|
@@ -198,17 +255,6 @@ export default defineNuxtPlugin({
|
|
|
198
255
|
function getTemplate(source, settings) {
|
|
199
256
|
return [settings ? `@use '${settings}';` : "", `@use '${source}';`].filter(Boolean).join("\n");
|
|
200
257
|
}
|
|
201
|
-
function resolveVuetifyConfigFile(configFile, nuxt) {
|
|
202
|
-
if (typeof configFile === "string" && !isAbsolute(configFile)) {
|
|
203
|
-
for (const layer of nuxt.options._layers) {
|
|
204
|
-
const resolved = resolve(layer.config.rootDir, configFile);
|
|
205
|
-
if (existsSync(resolved)) {
|
|
206
|
-
return resolved;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return configFile;
|
|
211
|
-
}
|
|
212
258
|
async function configureNuxt(configKey, nuxt, ctx) {
|
|
213
259
|
const {
|
|
214
260
|
styles,
|
|
@@ -223,9 +269,10 @@ async function configureNuxt(configKey, nuxt, ctx) {
|
|
|
223
269
|
nuxt.options.css ??= [];
|
|
224
270
|
if (typeof styles === "object" && "configFile" in styles) {
|
|
225
271
|
const configFile = resolveVuetifyConfigFile(styles.configFile, nuxt);
|
|
272
|
+
ctx.stylesConfigFile = await resolvePath(configFile);
|
|
226
273
|
const a = addTemplate({
|
|
227
274
|
filename: "vuetify.settings.scss",
|
|
228
|
-
getContents: async () => getTemplate("vuetify/styles",
|
|
275
|
+
getContents: async () => getTemplate("vuetify/styles", ctx.stylesConfigFile)
|
|
229
276
|
});
|
|
230
277
|
nuxt.options.css.push(a.dst);
|
|
231
278
|
} else if (ctx.vuetifyGte("4.0.0")) {
|
|
@@ -903,8 +950,8 @@ function vuetifySSRClientHintsPlugin(ctx) {
|
|
|
903
950
|
|
|
904
951
|
function vuetifyStylesPlugin(ctx) {
|
|
905
952
|
let configFile;
|
|
953
|
+
let vuetifyBase;
|
|
906
954
|
const options = { styles: ctx.moduleOptions.styles };
|
|
907
|
-
const vuetifyBase = resolveVuetifyBase();
|
|
908
955
|
const noneFiles = /* @__PURE__ */ new Set();
|
|
909
956
|
let isNone = false;
|
|
910
957
|
let sassVariables = false;
|
|
@@ -923,10 +970,11 @@ function vuetifyStylesPlugin(ctx) {
|
|
|
923
970
|
if (isObject(options.styles) && "configFile" in options.styles) {
|
|
924
971
|
sassVariables = true;
|
|
925
972
|
fileImport = semver.gt(ctx.viteVersion, "5.4.2");
|
|
926
|
-
configFile = await resolvePath(options.styles.configFile);
|
|
973
|
+
configFile = ctx.stylesConfigFile ?? await resolvePath(options.styles.configFile);
|
|
927
974
|
} else {
|
|
928
975
|
isNone = options.styles === "none";
|
|
929
976
|
}
|
|
977
|
+
vuetifyBase = await resolveVuetifyBase();
|
|
930
978
|
},
|
|
931
979
|
async resolveId(source, importer, { custom, ssr }) {
|
|
932
980
|
if (!sassVariables) {
|
|
@@ -939,7 +987,7 @@ function vuetifyStylesPlugin(ctx) {
|
|
|
939
987
|
const idx = source.indexOf("?");
|
|
940
988
|
return idx === -1 ? source : source.slice(0, idx);
|
|
941
989
|
}
|
|
942
|
-
if (importer && source.endsWith(".css") && isSubdir(vuetifyBase, path.isAbsolute(source) ? source : importer)) {
|
|
990
|
+
if (vuetifyBase && importer && source.endsWith(".css") && isSubdir(vuetifyBase, path.isAbsolute(source) ? source : importer)) {
|
|
943
991
|
let resolutionId;
|
|
944
992
|
if (source.startsWith(".")) {
|
|
945
993
|
resolutionId = path.resolve(path.dirname(importer), source);
|
|
@@ -972,6 +1020,9 @@ function vuetifyStylesPlugin(ctx) {
|
|
|
972
1020
|
},
|
|
973
1021
|
load(id) {
|
|
974
1022
|
if (sassVariables) {
|
|
1023
|
+
if (!vuetifyBase) {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
975
1026
|
const target = id.startsWith(PREFIX) ? path.resolve(vuetifyBase, id.slice(PREFIX.length)) : id.startsWith(SSR_PREFIX) ? path.resolve(vuetifyBase, id.slice(SSR_PREFIX.length)) : void 0;
|
|
976
1027
|
if (target) {
|
|
977
1028
|
const suffix = /\.scss/.test(target) ? ";\n" : "\n";
|
|
@@ -1314,7 +1365,7 @@ async function loadVuetifyConfiguration(cwd = process.cwd(), configOrPath = cwd,
|
|
|
1314
1365
|
inlineConfig = configOrPath;
|
|
1315
1366
|
configOrPath = process.cwd();
|
|
1316
1367
|
}
|
|
1317
|
-
const resolved = resolve
|
|
1368
|
+
const resolved = resolve(cwd, configOrPath);
|
|
1318
1369
|
let isFile = false;
|
|
1319
1370
|
if (existsSync(resolved) && statSync(resolved).isFile()) {
|
|
1320
1371
|
isFile = true;
|
|
@@ -1513,11 +1564,12 @@ async function prepareVuetifyStyles(nuxt, ctx) {
|
|
|
1513
1564
|
if (stylesConfig.experimental?.cache === false) {
|
|
1514
1565
|
return;
|
|
1515
1566
|
}
|
|
1516
|
-
const vuetifyBase = resolveVuetifyBase();
|
|
1567
|
+
const vuetifyBase = await resolveVuetifyBase();
|
|
1517
1568
|
let configFile;
|
|
1518
1569
|
let configContent = "";
|
|
1519
1570
|
if (stylesConfig.configFile) {
|
|
1520
|
-
configFile = await resolvePath(stylesConfig.configFile);
|
|
1571
|
+
configFile = await resolvePath(resolveVuetifyConfigFile(stylesConfig.configFile, nuxt));
|
|
1572
|
+
ctx.stylesConfigFile = configFile;
|
|
1521
1573
|
if (existsSync(configFile)) {
|
|
1522
1574
|
configContent = readFileSync(configFile, "utf8");
|
|
1523
1575
|
if (!ctx.vuetifyFilesToWatch.includes(configFile)) {
|
|
@@ -1528,18 +1580,15 @@ async function prepareVuetifyStyles(nuxt, ctx) {
|
|
|
1528
1580
|
if (!configFile) {
|
|
1529
1581
|
return;
|
|
1530
1582
|
}
|
|
1531
|
-
const hash =
|
|
1532
|
-
|
|
1533
|
-
|
|
1583
|
+
const hash = createStylesCacheHash(
|
|
1584
|
+
ctx.vuetifyVersion,
|
|
1585
|
+
ctx.viteVersion,
|
|
1586
|
+
configContent,
|
|
1587
|
+
configFile
|
|
1588
|
+
);
|
|
1589
|
+
const { stylesDir, cacheDir } = resolveStylesCachePaths(nuxt.options.rootDir, hash);
|
|
1534
1590
|
ctx.stylesCachePath = cacheDir;
|
|
1535
|
-
|
|
1536
|
-
const dirents = readdirSync(stylesDir, { withFileTypes: true });
|
|
1537
|
-
for (const dirent of dirents) {
|
|
1538
|
-
if (dirent.isDirectory() && dirent.name !== hash) {
|
|
1539
|
-
rmSync(join(stylesDir, dirent.name), { recursive: true, force: true });
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1591
|
+
cleanupOldStylesCaches(stylesDir, hash);
|
|
1543
1592
|
if (existsSync(cacheDir)) {
|
|
1544
1593
|
return;
|
|
1545
1594
|
}
|
|
@@ -1555,11 +1604,9 @@ async function prepareVuetifyStyles(nuxt, ctx) {
|
|
|
1555
1604
|
return;
|
|
1556
1605
|
}
|
|
1557
1606
|
}
|
|
1558
|
-
const files =
|
|
1559
|
-
findCssFiles(join(vuetifyBase, "lib/components"), files);
|
|
1560
|
-
findCssFiles(join(vuetifyBase, "lib/styles"), files);
|
|
1607
|
+
const files = collectVuetifyCssFiles(vuetifyBase);
|
|
1561
1608
|
for (const file of files) {
|
|
1562
|
-
const relativePath = relative
|
|
1609
|
+
const relativePath = relative(vuetifyBase, file);
|
|
1563
1610
|
const cacheFile = join(cacheDir, relativePath);
|
|
1564
1611
|
const sassFile = file.replace(/\.css$/, ".sass");
|
|
1565
1612
|
const scssFile = file.replace(/\.css$/, ".scss");
|
|
@@ -1582,8 +1629,8 @@ async function prepareVuetifyStyles(nuxt, ctx) {
|
|
|
1582
1629
|
loadPaths: [
|
|
1583
1630
|
dirname(configFile),
|
|
1584
1631
|
dirname(targetFile),
|
|
1585
|
-
resolve
|
|
1586
|
-
resolve
|
|
1632
|
+
resolve(vuetifyBase, ".."),
|
|
1633
|
+
resolve(vuetifyBase, "../.."),
|
|
1587
1634
|
// In case of monorepo/hoisting issues, but standard is enough
|
|
1588
1635
|
vuetifyBase
|
|
1589
1636
|
],
|
|
@@ -1604,24 +1651,6 @@ async function prepareVuetifyStyles(nuxt, ctx) {
|
|
|
1604
1651
|
};
|
|
1605
1652
|
writeFileSync(join(cacheDir, "metadata.json"), JSON.stringify(metadata, null, 2), "utf8");
|
|
1606
1653
|
}
|
|
1607
|
-
function findCssFiles(dir, fileList = []) {
|
|
1608
|
-
if (!existsSync(dir)) {
|
|
1609
|
-
return fileList;
|
|
1610
|
-
}
|
|
1611
|
-
const files = readdirSync(dir);
|
|
1612
|
-
for (const file of files) {
|
|
1613
|
-
const filePath = join(dir, file);
|
|
1614
|
-
const stat = statSync(filePath);
|
|
1615
|
-
if (stat.isDirectory()) {
|
|
1616
|
-
findCssFiles(filePath, fileList);
|
|
1617
|
-
} else {
|
|
1618
|
-
if (file.endsWith(".css")) {
|
|
1619
|
-
fileList.push(filePath);
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
return fileList;
|
|
1624
|
-
}
|
|
1625
1654
|
|
|
1626
1655
|
async function load(options, nuxt, ctx) {
|
|
1627
1656
|
const {
|
|
@@ -1704,7 +1733,7 @@ function registerWatcher(options, nuxt, ctx) {
|
|
|
1704
1733
|
if (nuxt.options.dev) {
|
|
1705
1734
|
let pageReload;
|
|
1706
1735
|
nuxt.hooks.hook("builder:watch", (_event, path) => {
|
|
1707
|
-
path = relative
|
|
1736
|
+
path = relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, path));
|
|
1708
1737
|
if (!pageReload && ctx.vuetifyFilesToWatch.includes(path)) {
|
|
1709
1738
|
return nuxt.callHook("restart");
|
|
1710
1739
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vuetify-nuxt-module",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-
|
|
4
|
+
"version": "1.0.0-beta.2",
|
|
5
5
|
"description": "Zero-Config Nuxt Module for Vuetify",
|
|
6
6
|
"author": "userquin <userquin@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"dev:prepare:date-io": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare ../../apps/date-io-playground",
|
|
135
135
|
"dev:date-io": "pnpm -C ../../apps/date-io-playground dev",
|
|
136
136
|
"docs:dev": "pnpm -C ../../docs run dev",
|
|
137
|
-
"docs:build": "
|
|
137
|
+
"docs:build": "pnpm -C ../../docs run build",
|
|
138
138
|
"docs:serve": "pnpm -C ../../docs run serve",
|
|
139
139
|
"lint": "eslint .",
|
|
140
140
|
"lint:fix": "nr lint --fix",
|