Skip to content

Commit

Permalink
chore: squash from #16018
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored and bluwy committed Mar 18, 2024
1 parent 72104f6 commit e00eb96
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 342 deletions.
121 changes: 30 additions & 91 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SOFTWARE.

# Licenses of bundled dependencies
The published Vite artifact additionally contains code with the following licenses:
Apache-2.0, BSD-2-Clause, CC0-1.0, ISC, MIT
Apache-2.0, BSD-2-Clause, ISC, MIT

# Bundled dependencies:
## @ampproject/remapping
Expand Down Expand Up @@ -2055,61 +2055,6 @@ Repository: https:/webpack/loader-utils.git
---------------------------------------

## lodash.camelcase
License: MIT
By: John-David Dalton, Blaine Bublitz, Mathias Bynens
Repository: lodash/lodash

> Copyright jQuery Foundation and other contributors <https://jquery.org/>
>
> Based on Underscore.js, copyright Jeremy Ashkenas,
> DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
>
> This software consists of voluntary contributions made by many
> individuals. For exact contribution history, see the revision history
> available at https:/lodash/lodash
>
> The following license applies to all parts of this software except as
> documented below:
>
> ====
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
>
> ====
>
> Copyright and related rights for sample code are waived via CC0. Sample
> code is defined as all source code displayed within the prose of the
> documentation.
>
> CC0: http://creativecommons.org/publicdomain/zero/1.0/
>
> ====
>
> Files located in the node_modules and vendor directories are externally
> maintained libraries used by this software which have their own
> licenses; we recommend you read them, as their terms may differ from the
> terms above.
---------------------------------------

## magic-string
License: MIT
By: Rich Harris
Expand Down Expand Up @@ -2645,34 +2590,6 @@ Repository: postcss/postcss-load-config
---------------------------------------

## postcss-modules
License: MIT
By: Alexander Madyankin
Repository: https:/css-modules/postcss-modules.git

> The MIT License (MIT)
>
> Copyright 2015-present Alexander Madyankin <[email protected]>
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of
> this software and associated documentation files (the "Software"), to deal in
> the Software without restriction, including without limitation the rights to
> use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
> the Software, and to permit persons to whom the Software is furnished to do so,
> subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
> FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
> COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
> IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## postcss-modules-extract-imports
License: ISC
By: Glen Maddern
Expand Down Expand Up @@ -3107,13 +3024,6 @@ Repository: jshttp/statuses
---------------------------------------

## string-hash
License: CC0-1.0
By: The Dark Sky Company
Repository: git:/darkskyapp/string-hash.git

---------------------------------------

## strip-ansi
License: MIT
By: Sindre Sorhus
Expand Down Expand Up @@ -3420,6 +3330,35 @@ Repository: jshttp/vary
---------------------------------------

## vite-css-modules
License: MIT
By: Hiroki Osame
Repository: privatenumber/vite-css-modules

> MIT License
>
> Copyright (c) Hiroki Osame <[email protected]>
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
---------------------------------------

## which
License: ISC
By: Isaac Z. Schlueter
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
"picomatch": "^2.3.1",
"postcss-import": "^16.0.1",
"postcss-load-config": "^4.0.2",
"postcss-modules": "^6.0.0",
"resolve.exports": "^2.0.2",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
Expand All @@ -152,6 +151,7 @@
"tslib": "^2.6.2",
"types": "link:./types",
"ufo": "^1.5.1",
"vite-css-modules": "^1.4.2",
"ws": "^8.16.0"
},
"peerDependencies": {
Expand Down
108 changes: 1 addition & 107 deletions packages/vite/src/node/__tests__/plugins/css.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { describe, expect, test, vi } from 'vitest'
import { resolveConfig } from '../../config'
import type { InlineConfig } from '../../config'
import { describe, expect, test } from 'vitest'
import {
convertTargets,
cssPlugin,
cssUrlRE,
getEmptyChunkReplacer,
hoistAtRules,
Expand Down Expand Up @@ -53,71 +48,6 @@ describe('search css url function', () => {
})
})

describe('css modules', () => {
test('css module compose/from path resolutions', async () => {
const mockedProjectPath = path.join(process.cwd(), '/foo/bar/project')
const { transform, resetMock } = await createCssPluginTransform(
{
[path.join(mockedProjectPath, '/css/bar.module.css')]: `\
.bar {
display: block;
background: #f0f;
}`,
},
{
resolve: {
alias: [
{
find: '@',
replacement: mockedProjectPath,
},
],
},
},
)

const result = await transform(
`\
.foo {
position: fixed;
composes: bar from '@/css/bar.module.css';
}`,
'/css/foo.module.css',
)

expect(result.code).toBe(
`\
._bar_1csqm_1 {
display: block;
background: #f0f;
}
._foo_86148_1 {
position: fixed;
}`,
)

resetMock()
})

test('custom generateScopedName', async () => {
const { transform, resetMock } = await createCssPluginTransform(undefined, {
css: {
modules: {
generateScopedName: 'custom__[hash:base64:5]',
},
},
})
const css = `\
.foo {
color: red;
}`
const result1 = await transform(css, '/foo.module.css') // server
const result2 = await transform(css, '/foo.module.css?direct') // client
expect(result1.code).toBe(result2.code)
resetMock()
})
})

describe('hoist @ rules', () => {
test('hoist @import', async () => {
const css = `.foo{color:red;}@import "bla";`
Expand Down Expand Up @@ -208,42 +138,6 @@ describe('hoist @ rules', () => {
})
})

async function createCssPluginTransform(
files?: Record<string, string>,
inlineConfig: InlineConfig = {},
) {
const config = await resolveConfig(inlineConfig, 'serve')
const { transform, buildStart } = cssPlugin(config)

// @ts-expect-error buildStart is function
await buildStart.call({})

const mockFs = vi
.spyOn(fs, 'readFile')
// @ts-expect-error vi.spyOn not recognize override `fs.readFile` definition.
.mockImplementationOnce((p, encoding, callback) => {
callback(null, Buffer.from(files?.[p] ?? ''))
})

return {
async transform(code: string, id: string) {
// @ts-expect-error transform is function
return await transform.call(
{
addWatchFile() {
return
},
},
code,
id,
)
},
resetMock() {
mockFs.mockReset()
},
}
}

describe('convertTargets', () => {
test('basic cases', () => {
expect(convertTargets('es2018')).toStrictEqual({
Expand Down
Loading

0 comments on commit e00eb96

Please sign in to comment.