Skip to content

Commit

Permalink
chore: fix vuetify package build on Windows (#20293)
Browse files Browse the repository at this point in the history
Co-authored-by: Kael <kaelwd@gmail.com>
  • Loading branch information
userquin and KaelWD committed Aug 15, 2024
1 parent 294cc73 commit e4ce28d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
41 changes: 18 additions & 23 deletions packages/vuetify/build/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { posix as path } from 'path'
import path from 'upath'
import { mkdirp } from 'mkdirp'
import { writeFile } from 'fs/promises'
import { fileURLToPath } from 'url'
Expand All @@ -23,13 +23,10 @@ const banner = `/*!
* Released under the MIT License.
*/\n`

function fixWindowsPath(path) {
return path.replace(/^[^:]+:\\/, '\\').replaceAll('\\', '/')
}

const srcDir = fixWindowsPath(fileURLToPath(new URL('../src', import.meta.url)));
const libDir = fixWindowsPath(fileURLToPath(new URL('../lib', import.meta.url)));
const labsDir = fixWindowsPath(fileURLToPath(new URL('../src/labs', import.meta.url)));
const root = path.resolve(fileURLToPath(import.meta.url), '../..')
const srcDir = path.resolve(root, 'src')
const libDir = path.resolve(root, 'lib')
const labsDir = path.resolve(srcDir, 'labs')

export default [
{
Expand Down Expand Up @@ -74,7 +71,7 @@ export default [
},
output (styles, styleNodes) {
// Complete CSS bundle
mkdirp(fileURLToPath(new URL('../dist', import.meta.url))).then(() => {
mkdirp(path.resolve(root, 'dist')).then(() => {
return Promise.all([
postcss([autoprefixer]).process(styles, { from: 'src' }),
postcss([autoprefixer, cssnano({
Expand All @@ -84,13 +81,13 @@ export default [
})]).process(styles, { from: 'src' }),
])
}).then(result => {
writeFile(fileURLToPath(new URL('../dist/vuetify.css', import.meta.url)), banner + result[0].css, 'utf8')
writeFile(fileURLToPath(new URL('../dist/vuetify.min.css', import.meta.url)), banner + result[1].css, 'utf8')
writeFile(path.resolve(root, 'dist/vuetify.css'), banner + result[0].css, 'utf8')
writeFile(path.resolve(root, 'dist/vuetify.min.css'), banner + result[1].css, 'utf8')
})

// Individual CSS files
for (const {id, content} of styleNodes) {
const relativePath = path.relative(srcDir, fixWindowsPath(id))
const relativePath = path.relative(srcDir, id)
const out = path.parse(path.join(libDir, relativePath))
mkdirp(out.dir).then(() => {
writeFile(path.join(out.dir, out.name + '.css'), content, 'utf8')
Expand All @@ -114,8 +111,7 @@ export default [
(await this.resolve('src/components/index.ts')).id
)
await Promise.all(importedIds.map(async id => {
// Fix for Windows
const importFrom = path.relative(fileURLToPath(new URL('../src', import.meta.url)), fixWindowsPath(id)).replace(/\.ts$/, '.mjs')
const importFrom = path.relative(srcDir, id).replace(/\.ts$/, '.mjs')

if (await this.resolve(path.join(id, '../_variables.scss')) != null) {
variables.push(id)
Expand Down Expand Up @@ -171,7 +167,7 @@ export default [
source: variables.map(id => {
return `@forward '` + path.join(
'../lib',
path.relative(fileURLToPath(new URL('../src', import.meta.url)), id),
path.relative(srcDir, id),
'../_variables.scss'
) + `'`
}).sort().join('\n'),
Expand Down Expand Up @@ -209,7 +205,7 @@ export default [
charset: false,
},
output (styles, styleNodes) {
mkdirp(fileURLToPath(new URL('../dist', import.meta.url))).then(() => {
mkdirp(path.resolve(root, 'dist')).then(() => {
return Promise.all([
postcss([autoprefixer]).process(styles, { from: 'src' }),
postcss([autoprefixer, cssnano({
Expand All @@ -219,17 +215,17 @@ export default [
})]).process(styles, { from: 'src' }),
])
}).then(result => {
writeFile(fileURLToPath(new URL('../dist/vuetify-labs.css', import.meta.url)), banner + result[0].css, 'utf8')
writeFile(fileURLToPath(new URL('../dist/vuetify-labs.min.css', import.meta.url)), banner + result[1].css, 'utf8')
writeFile(path.resolve(root, 'dist/vuetify-labs.css'), banner + result[0].css, 'utf8')
writeFile(path.resolve(root, 'dist/vuetify-labs.min.css'), banner + result[1].css, 'utf8')
})

// Individual CSS files
styleNodes = styleNodes.filter(node => {
return fixWindowsPath(node.id).startsWith(labsDir)
return node.id.startsWith(labsDir)
}
);
for (const { id, content } of styleNodes) {
const relativePath = path.relative(srcDir, fixWindowsPath(id))
const relativePath = path.relative(srcDir, id)
const out = path.parse(path.join(libDir, relativePath))
mkdirp(out.dir).then(() => {
writeFile(path.join(out.dir, out.name + '.css'), content, 'utf8')
Expand All @@ -252,8 +248,7 @@ export default [
(await this.resolve('src/labs/components.ts')).id
)
await Promise.all(importedIds.map(async id => {
// Fix for Windows
const importFrom = path.relative(fileURLToPath(new URL('../src', import.meta.url)), fixWindowsPath(id)).replace(/\.ts$/, '.mjs')
const importFrom = path.relative(srcDir, id).replace(/\.ts$/, '.mjs')

if (await this.resolve(path.join(id, '../_variables.scss')) != null) {
variables.push(id)
Expand Down Expand Up @@ -290,7 +285,7 @@ export default [
source: variables.map(id => {
return `@forward '` + path.join(
'../lib',
path.relative(fileURLToPath(new URL('../src', import.meta.url)), id),
path.relative(srcDir, id),
'../_variables.scss'
) + `'`
}).sort().join('\n'),
Expand Down
1 change: 1 addition & 0 deletions packages/vuetify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"rollup-plugin-terser": "^7.0.2",
"timezone-mock": "^1.3.6",
"unplugin-vue-components": "^0.27.4",
"upath": "^2.0.1",
"vite": "^5.4.0",
"vite-ssr": "^0.17.1",
"vue-i18n": "^9.7.1",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4ce28d

Please sign in to comment.