-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b98eae3
commit f986670
Showing
15 changed files
with
621 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"compilerOptions": { | ||
"paths": { | ||
"@wyw-in-js/object-syntax": ["./examples/object-syntax/src/index.ts"], | ||
"@wyw-in-js/processor-utils": ["./packages/processor-utils/src/index.ts"], | ||
"@wyw-in-js/shared": ["./packages/shared/src/index.ts"], | ||
"@wyw-in-js/transform": ["./packages/transform/src/index.ts"], | ||
"@wyw-in-js/template-tag-syntax": [ | ||
"./examples/template-tag-syntax/src/index.ts" | ||
], | ||
"@wyw-in-js/webpack-loader": ["./packages/webpack-loader/src/index.ts"], | ||
"@wyw-in-js/vite": ["./packages/vite/src/index.ts"] | ||
} | ||
}, | ||
"display": "Aliases configuration" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.c2tf5um { | ||
color: red; | ||
background: green; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
<script src="./src/index.ts" type="module"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@wyw-in-js/e2e-vite", | ||
"version": "0.1.1", | ||
"dependencies": { | ||
"@wyw-in-js/template-tag-syntax": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@wyw-in-js/ts-config": "workspace:*", | ||
"@wyw-in-js/vite": "workspace:*", | ||
"picocolors": "^1.0.0", | ||
"tsconfig-paths": "^4.2.0", | ||
"ts-node": "^10.2.9", | ||
"vite": "^5.0.9" | ||
}, | ||
"private": true, | ||
"scripts": { | ||
"test": "node -r ts-node/register ./scripts/test.cjs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// @ts-check | ||
|
||
const fs = require('node:fs/promises'); | ||
const path = require('node:path'); | ||
const colors = require('picocolors'); | ||
const prettier = require('prettier'); | ||
const { build } = require('vite'); | ||
const wyw = require('@wyw-in-js/vite'); | ||
|
||
const PKG_DIR = path.resolve(__dirname, '..'); | ||
const DIST_DIR = path.resolve(PKG_DIR, 'dist'); | ||
|
||
/** | ||
* @param {string} value | ||
* @returns {string} | ||
*/ | ||
function normalizeLineEndings(value) { | ||
return value.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); | ||
} | ||
|
||
async function buildArtefact() { | ||
await build({ | ||
build: { | ||
manifest: true, | ||
outDir: DIST_DIR, | ||
}, | ||
configFile: false, | ||
plugins: [wyw.default()], | ||
}); | ||
} | ||
|
||
async function getCSSFromManifest() { | ||
const manifestPath = path.resolve(DIST_DIR, '.vite', 'manifest.json'); | ||
const manifest = require(manifestPath); | ||
|
||
if (!manifest['index.html']) { | ||
throw new Error('No index.html in manifest'); | ||
} | ||
|
||
if (!manifest['index.html'].css) { | ||
throw new Error('No CSS in manifest'); | ||
} | ||
|
||
if (manifest['index.html'].css.length !== 1) { | ||
throw new Error('More than one CSS in manifest'); | ||
} | ||
|
||
const cssFilePath = path.resolve(DIST_DIR, manifest['index.html'].css[0]); | ||
const cssSnapshot = await fs.readFile(cssFilePath, 'utf-8'); | ||
|
||
return prettier.format(cssSnapshot, { | ||
parser: 'css', | ||
}); | ||
} | ||
|
||
async function main() { | ||
console.log(colors.blue('Package directory:'), PKG_DIR); | ||
|
||
try { | ||
await fs.rm(DIST_DIR, { recursive: true }); | ||
} catch (err) {} | ||
|
||
await buildArtefact(); | ||
|
||
const cssOutput = normalizeLineEndings(await getCSSFromManifest()); | ||
const cssFixture = normalizeLineEndings( | ||
await fs.readFile(path.resolve(PKG_DIR, 'fixture.css'), 'utf-8') | ||
); | ||
|
||
if (cssOutput !== cssFixture) { | ||
console.log(colors.red('Output CSS:')); | ||
console.log(cssOutput); | ||
console.log(colors.red('Expected CSS:')); | ||
console.log(cssFixture); | ||
|
||
throw new Error('CSS output does not match fixture'); | ||
} | ||
} | ||
|
||
main().then( | ||
() => { | ||
console.log(colors.green('✅ Vite E2E test passed')); | ||
process.exit(0); | ||
}, | ||
(error) => { | ||
console.error(colors.red('Error:'), error); | ||
process.exit(1); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { css } from '@wyw-in-js/template-tag-syntax'; | ||
|
||
const classA = css` | ||
color: red; | ||
background: green; | ||
`; | ||
|
||
export { classA }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "@wyw-in-js/ts-config/node.json", | ||
"files": [], | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"rootDir": "../..", | ||
"baseUrl": "../.." | ||
}, | ||
"include": ["./src/*", "./scripts/*"], | ||
"ts-node": { | ||
"transpileOnly": true, | ||
"require": ["tsconfig-paths/register"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.