-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for more export expressions
Refs #60
- Loading branch information
1 parent
cab989a
commit 41e8bb2
Showing
12 changed files
with
178 additions
and
92 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import test from './test.css'; | ||
export default test; | ||
|
||
export default test; |
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,2 @@ | ||
export default (() => | ||
'.test {\n color: white;\n background: url("./test.jpg");\n}\n\n.test:after {\n content: "\\2014";\n}\n')(); |
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 @@ | ||
export default '.test {\n color: white;\n background: url("./test.jpg");\n}\n\n.test:after {\n content: "\\2014";\n}\n'; |
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,3 @@ | ||
const css = `.test {\n color: white;\n background: url("./test.jpg");\n}\n\n.test:after {\n content: "\\2014";\n}\n`; | ||
|
||
export default css; |
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 @@ | ||
export default `.test {\n color: white;\n background: url("./test.jpg");\n}\n\n.test:after {\n content: "\\2014";\n}\n`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,91 @@ | ||
import {readFileSync} from 'fs'; | ||
import postcss from 'rollup-plugin-postcss'; | ||
import virtual from '@rollup/plugin-virtual'; | ||
import { strict as assert } from 'assert'; | ||
import { readFileSync, rmSync } from 'fs'; | ||
import { globSync } from 'glob'; | ||
import { CSSResult } from 'lit'; | ||
import * as rollup from 'rollup'; | ||
import {CSSResult} from 'lit'; | ||
import {strict as assert} from 'assert'; | ||
import postcss from 'rollup-plugin-postcss'; | ||
import postcssLit from '../dist/index.js'; | ||
|
||
const cssFile = './test/test.css'; | ||
const entry = './test/entry.mjs'; | ||
const readFile = (path) => readFileSync(path, 'utf-8'); | ||
const readFile = path => readFileSync(path, 'utf-8'); | ||
|
||
describe('rollup-plugin-postcss-lit', () => { | ||
it('should wrap an exported style string in the css template literal tag', async () => { | ||
const outFile = 'out.mjs'; | ||
const cssText = readFile(cssFile); | ||
await renderFile(entry, `./test/${outFile}`,[ | ||
postcss({ | ||
inject: false, | ||
}), | ||
postcssLit(), | ||
]); | ||
const litStyle = await import(`./${outFile}`).then(m => m.default); | ||
assert.ok(litStyle instanceof CSSResult); | ||
assert.equal(litStyle.cssText, cssText); | ||
it('should wrap an exported style string in the css template literal tag', async () => { | ||
const outFile = 'out.mjs'; | ||
const cssText = readFile(cssFile); | ||
await renderFile(entry, `./test/${outFile}`, [ | ||
postcss({ | ||
inject: false, | ||
}), | ||
postcssLit(), | ||
]); | ||
const litStyle = await import(`./${outFile}`).then(m => m.default); | ||
assert.ok(litStyle instanceof CSSResult); | ||
assert.equal(litStyle.cssText, cssText); | ||
|
||
const outFileText = readFile(`./test/${outFile}`); | ||
const hasLitImport = outFileText.includes(`from 'lit';`); | ||
assert.ok(hasLitImport); | ||
}); | ||
const outFileText = readFile(`./test/${outFile}`); | ||
const hasLitImport = outFileText.includes(`from 'lit';`); | ||
assert.ok(hasLitImport); | ||
}); | ||
|
||
it('should wrap a default export literal', async () => { | ||
const outFile = 'out-literal.mjs'; | ||
const intermediateFile = 'test-literal.mjs'; | ||
await renderFile('./test/entry-literal.mjs', `./test/${outFile}`,[ | ||
postcssLit({ include: `**/${intermediateFile}` }), | ||
]); | ||
const cssText = await import(`./${intermediateFile}`).then(m => m.default); | ||
const litStyle = await import(`./${outFile}`).then(m => m.default); | ||
assert.ok(litStyle instanceof CSSResult); | ||
assert.equal(litStyle.cssText, cssText); | ||
}); | ||
it('should support different export expressions', async () => { | ||
for (const intermediateFile of globSync('./intermediate-?(*).mjs', { | ||
cwd: './test', | ||
})) { | ||
const outFile = intermediateFile.replace('intermediate', 'out'); | ||
const input = 'virtual-entry.mjs'; | ||
const bundle = await rollup.rollup({ | ||
input, | ||
plugins: [ | ||
virtual({ | ||
[input]: `import test from './test/${intermediateFile}'; export default test;`, | ||
}), | ||
postcssLit({ include: `**/${intermediateFile}` }), | ||
], | ||
}); | ||
await bundle.write({ | ||
file: `./test/${outFile}`, | ||
format: 'es', | ||
}); | ||
const cssText = await import(`./${intermediateFile}`).then( | ||
m => m.default, | ||
); | ||
const litStyle = await import(`./${outFile}`).then(m => m.default); | ||
assert.ok(litStyle instanceof CSSResult); | ||
assert.equal(litStyle.cssText, cssText); | ||
} | ||
}); | ||
|
||
it('can accept a different import package', async () => { | ||
const outFile = './test/out-import.mjs'; | ||
await renderFile(entry, outFile,[ | ||
postcss({ | ||
inject: false, | ||
}), | ||
postcssLit({ | ||
importPackage: 'lit-element', | ||
}), | ||
]); | ||
it('can accept a different import package', async () => { | ||
const outFile = './test/out-import.mjs'; | ||
await renderFile(entry, outFile, [ | ||
postcss({ | ||
inject: false, | ||
}), | ||
postcssLit({ | ||
importPackage: 'lit-element', | ||
}), | ||
]); | ||
|
||
const outFileText = readFile(outFile); | ||
const hasLitElementImport = outFileText.includes(`from 'lit-element';`); | ||
assert.ok(hasLitElementImport); | ||
}); | ||
const outFileText = readFile(outFile); | ||
const hasLitElementImport = outFileText.includes(`from 'lit-element';`); | ||
assert.ok(hasLitElementImport); | ||
}); | ||
|
||
after(() => { | ||
globSync('./test/out*').forEach(f => rmSync(f)); | ||
}); | ||
}); | ||
|
||
const renderFile = async (inFile, outFile, plugins) => { | ||
const bundle = await rollup.rollup({ | ||
input: inFile, | ||
plugins, | ||
}); | ||
await bundle.write({ | ||
file: outFile, | ||
format: 'es', | ||
}); | ||
const bundle = await rollup.rollup({ | ||
input: inFile, | ||
plugins, | ||
}); | ||
await bundle.write({ | ||
file: outFile, | ||
format: 'es', | ||
}); | ||
}; |
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 |
---|---|---|
|
@@ -8,6 +8,5 @@ | |
"declaration": true, | ||
"skipLibCheck": true, | ||
"outDir": "dist" | ||
}, | ||
"files": [ "index.ts"] | ||
} | ||
} |
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,12 @@ | ||
import 'estree'; | ||
|
||
declare module 'estree' { | ||
export interface BaseNodeWithoutComments { | ||
edit: { | ||
source: () => string; | ||
update: (replacement: string) => Node; | ||
append: (append: string) => Node; | ||
prepend: (prepend: string) => Node; | ||
}; | ||
} | ||
} |