Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve assets handling and support vanilla extract styles. (#240)
* Add fixture. * Work. * Add tests. * Update deps. * Fix css external.
- Loading branch information
Showing
17 changed files
with
673 additions
and
270 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
12 changes: 0 additions & 12 deletions
12
.yarn/patches/@rollup-plugin-commonjs-npm-22.0.2-6275b92096.patch
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
.yarn/patches/@rollup-plugin-node-resolve-npm-13.3.0-a93dd11647.patch
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 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
173 changes: 173 additions & 0 deletions
173
packages/packemon/tests/__snapshots__/assets.test.ts.snap
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,173 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`vanilla extract > bundle + compile > assets/src/styles.css.ts.vanilla.css 1`] = ` | ||
".styles_redText__exh0q70 { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`vanilla extract > bundle + compile > assets/src/styles.css.ts.vanilla.css 2`] = ` | ||
".styles_redText__exh0q70 { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`vanilla extract > bundle + compile > esm/index.js 1`] = ` | ||
"// Bundled with Packemon: https://packemon.dev | ||
// Platform: browser, Support: stable, Format: esm | ||
import './assets/src/styles.css.ts.vanilla.css'; | ||
var redText = 'styles_redText__exh0q70'; | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: redText | ||
}, props)); | ||
export { MyComponent }; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > bundle + compile > lib/index.js 1`] = ` | ||
"// Bundled with Packemon: https://packemon.dev | ||
// Platform: browser, Support: stable, Format: lib | ||
'use strict'; | ||
require('./assets/src/styles.css.ts.vanilla.css'); | ||
var redText = 'styles_redText__exh0q70'; | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: redText | ||
}, props)); | ||
exports.MyComponent = MyComponent; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > bundle + no compile > esm/index.js 1`] = ` | ||
"// Bundled with Packemon: https://packemon.dev | ||
// Platform: browser, Support: stable, Format: esm | ||
import { style } from '@vanilla-extract/css'; | ||
const redText = style({ | ||
color: 'red' | ||
}); | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: redText | ||
}, props)); | ||
export { MyComponent }; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > bundle + no compile > lib/index.js 1`] = ` | ||
"// Bundled with Packemon: https://packemon.dev | ||
// Platform: browser, Support: stable, Format: lib | ||
'use strict'; | ||
const css = require('@vanilla-extract/css'); | ||
const redText = css.style({ | ||
color: 'red' | ||
}); | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: redText | ||
}, props)); | ||
exports.MyComponent = MyComponent; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + compile > assets/src/styles.css.ts.vanilla.css 1`] = ` | ||
".styles_redText__exh0q70 { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + compile > assets/src/styles.css.ts.vanilla.css 2`] = ` | ||
".styles_redText__exh0q70 { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + compile > esm/index.js 1`] = ` | ||
"import { redText } from './styles.css.js'; | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: redText | ||
}, props)); | ||
export { MyComponent }; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + compile > esm/styles.css.js 1`] = ` | ||
"import './assets/src/styles.css.ts.vanilla.css'; | ||
var redText = 'styles_redText__exh0q70'; | ||
export { redText }; | ||
//# sourceMappingURL=styles.css.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + compile > lib/index.js 1`] = ` | ||
"'use strict'; | ||
const styles_css = require('./styles.css.js'); | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: styles_css.redText | ||
}, props)); | ||
exports.MyComponent = MyComponent; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + compile > lib/styles.css.js 1`] = ` | ||
"'use strict'; | ||
require('./assets/src/styles.css.ts.vanilla.css'); | ||
var redText = 'styles_redText__exh0q70'; | ||
exports.redText = redText; | ||
//# sourceMappingURL=styles.css.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + no compile > esm/index.js 1`] = ` | ||
"import { redText } from './styles.css.js'; | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: redText | ||
}, props)); | ||
export { MyComponent }; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + no compile > esm/styles.css.js 1`] = ` | ||
"import { style } from '@vanilla-extract/css'; | ||
const redText = style({ | ||
color: 'red' | ||
}); | ||
export { redText }; | ||
//# sourceMappingURL=styles.css.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + no compile > lib/index.js 1`] = ` | ||
"'use strict'; | ||
const styles_css = require('./styles.css.js'); | ||
const MyComponent = props => /*#__PURE__*/React.createElement("div", Object.assign({ | ||
className: styles_css.redText | ||
}, props)); | ||
exports.MyComponent = MyComponent; | ||
//# sourceMappingURL=index.js.map | ||
" | ||
`; | ||
|
||
exports[`vanilla extract > no bundle + no compile > lib/styles.css.js 1`] = ` | ||
"'use strict'; | ||
const css = require('@vanilla-extract/css'); | ||
const redText = css.style({ | ||
color: 'red' | ||
}); | ||
exports.redText = redText; | ||
//# sourceMappingURL=styles.css.js.map | ||
" | ||
`; |
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,100 @@ | ||
import { InputPluginOption } from 'rollup'; | ||
import { describe, it, vi } from 'vitest'; | ||
import { Path } from '@boost/common'; | ||
import { vanillaExtractPlugin } from '@vanilla-extract/rollup-plugin'; | ||
import { Artifact } from '../src'; | ||
import { getFixturePath, loadPackageAtPath, snapshotPackageBuildOutputs } from './helpers'; | ||
|
||
vi.setConfig({ testTimeout: 30_000 }); | ||
|
||
describe('vanilla extract', () => { | ||
it('no bundle + compile', async () => { | ||
const root = new Path(getFixturePath('project-assets-vanilla')); | ||
const pkg = loadPackageAtPath(root); | ||
|
||
const index = new Artifact(pkg, [{ format: 'lib' }, { format: 'esm' }]); | ||
index.bundle = false; | ||
index.platform = 'browser'; | ||
index.support = 'stable'; | ||
index.inputs = { index: 'src/index.tsx' }; | ||
|
||
pkg.artifacts.push(index); | ||
|
||
await pkg.build( | ||
{ addEntries: false }, | ||
{ | ||
rollupInput(config) { | ||
(config.plugins as InputPluginOption[]).push( | ||
vanillaExtractPlugin({ | ||
cwd: root.path(), | ||
}), | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
snapshotPackageBuildOutputs(pkg); | ||
}); | ||
|
||
it('bundle + compile', async () => { | ||
const root = new Path(getFixturePath('project-assets-vanilla')); | ||
const pkg = loadPackageAtPath(root); | ||
|
||
const index = new Artifact(pkg, [{ format: 'lib' }, { format: 'esm' }]); | ||
index.bundle = true; | ||
index.platform = 'browser'; | ||
index.support = 'stable'; | ||
index.inputs = { index: 'src/index.tsx' }; | ||
|
||
pkg.artifacts.push(index); | ||
|
||
await pkg.build( | ||
{ addEntries: false }, | ||
{ | ||
rollupInput(config) { | ||
(config.plugins as InputPluginOption[]).push( | ||
vanillaExtractPlugin({ | ||
cwd: root.path(), | ||
}), | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
snapshotPackageBuildOutputs(pkg); | ||
}); | ||
|
||
it('no bundle + no compile', async () => { | ||
const root = new Path(getFixturePath('project-assets-vanilla')); | ||
const pkg = loadPackageAtPath(root); | ||
|
||
const index = new Artifact(pkg, [{ format: 'lib' }, { format: 'esm' }]); | ||
index.bundle = false; | ||
index.platform = 'browser'; | ||
index.support = 'stable'; | ||
index.inputs = { index: 'src/index.tsx' }; | ||
|
||
pkg.artifacts.push(index); | ||
|
||
await pkg.build({ addEntries: false }, {}); | ||
|
||
snapshotPackageBuildOutputs(pkg); | ||
}); | ||
|
||
it('bundle + no compile', async () => { | ||
const root = new Path(getFixturePath('project-assets-vanilla')); | ||
const pkg = loadPackageAtPath(root); | ||
|
||
const index = new Artifact(pkg, [{ format: 'lib' }, { format: 'esm' }]); | ||
index.bundle = true; | ||
index.platform = 'browser'; | ||
index.support = 'stable'; | ||
index.inputs = { index: 'src/index.tsx' }; | ||
|
||
pkg.artifacts.push(index); | ||
|
||
await pkg.build({ addEntries: false }, {}); | ||
|
||
snapshotPackageBuildOutputs(pkg); | ||
}); | ||
}); |
Oops, something went wrong.