Skip to content

Commit

Permalink
fix(plugin): ensure external plugin css do not require physical file
Browse files Browse the repository at this point in the history
Closes #2622
  • Loading branch information
adamdbradley committed Aug 12, 2020
1 parent 0b71cdd commit b5a2536
Show file tree
Hide file tree
Showing 8 changed files with 2,437 additions and 63 deletions.
4 changes: 4 additions & 0 deletions src/compiler/bundle/ext-transforms-plugin.ts
Expand Up @@ -21,6 +21,10 @@ export const extTransformsPlugin = (config: d.Config, compilerCtx: d.CompilerCtx
let cmp: d.ComponentCompilerMeta;
const filePath = normalizeFsPath(id);
const code = await compilerCtx.fs.readFile(filePath);
if (typeof code !== 'string') {
return null;
}

const pluginTransforms = await runPluginTransformsEsmImports(config, compilerCtx, buildCtx, code, filePath);
const commentOriginalSelector = bundleOpts.platform === 'hydrate' && data.encapsulation === 'shadow';

Expand Down
2,403 changes: 2,372 additions & 31 deletions test/end-to-end/package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions test/end-to-end/package.json
Expand Up @@ -19,15 +19,17 @@
"preset": "../../testing/jest-preset.js"
},
"devDependencies": {
"@stencil/react-output-target": "^0.0.7",
"@stencil/react-output-target": "^0.0.9",
"@types/file-saver": "^2.0.1",
"@types/lodash": "^4.14.157",
"@types/lodash": "^4.14.159",
"@types/lodash-es": "^4.17.3",
"@types/video.js": "^7.3.10",
"file-saver": "^2.0.2",
"lodash": "^4.17.15",
"linaria": "^1.3.3",
"lodash": "^4.17.19",
"lodash-es": "^4.17.15",
"rollup-plugin-css-only": "^2.1.0",
"rollup-plugin-node-builtins": "^2.1.2",
"video.js": "^7.8.3"
"video.js": "^7.8.4"
}
}
12 changes: 11 additions & 1 deletion test/end-to-end/src/app-root/app-root.e2e.ts
Expand Up @@ -58,7 +58,7 @@ describe('goto root url', () => {

it('should apply global style when setting html', async () => {
const page = await newE2EPage({
html: '<app-root></app-root>',
url: '/',
});

const elm = await page.find('app-root');
Expand All @@ -67,5 +67,15 @@ describe('goto root url', () => {
expect(elmStyle.borderColor).toBe('rgb(255, 0, 0)');
expect(elmStyle.borderWidth).toBe('5px');
expect(elmStyle.borderStyle).toBe('dotted');

const videoElm = await page.find('#video');
const videoStyle = await videoElm.getComputedStyle();

// @Component() styles
expect(videoStyle.borderColor).toBe('rgb(0, 0, 255)');
expect(videoStyle.borderWidth).toBe('2px');

// linaria styles
expect(videoStyle.backgroundColor).toBe('rgba(0, 0, 255, 0.1)');
});
});
13 changes: 0 additions & 13 deletions test/end-to-end/src/app-root/app-root.spec.ts

This file was deleted.

19 changes: 18 additions & 1 deletion test/end-to-end/src/app-root/app-root.tsx
Expand Up @@ -2,13 +2,30 @@ import { Component, State, h, Host, Listen } from '@stencil/core';
import _ from 'lodash';
import _es from 'lodash-es';
import videojs from 'video.js';
import { css } from 'linaria';

const linariaCss = css`
background-color: rgba(0, 0, 255, 0.1);
`;

const styles = `
#video {
position: absolute;
top: 400px;
width: 80%;
height: 300px;
border: 2px solid blue;
padding: 10px;
}
`;

function format(target: any, propertyKey: string) {
console.log(target, propertyKey);
}

@Component({
tag: 'app-root',
styles,
})
export class AppRoot {
@format something = '12';
Expand Down Expand Up @@ -36,7 +53,7 @@ export class AppRoot {
return (
<Host>
<prop-cmp first={this.first} lastName={this.last} mode="ios" />
<div id="video"></div>
<div id="video" class={linariaCss}></div>
</Host>
);
}
Expand Down
22 changes: 14 additions & 8 deletions test/end-to-end/src/index.html
@@ -1,8 +1,14 @@
<!doctype html>
<meta charset="UTF-8">

<link rel="stylesheet" href="/build/endtoend.css">
<script type="module" src="/build/endtoend.esm.js"></script>
<script nomodule src="/build/endtoend.js"></script>

<app-root></app-root>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>E2E</title>
<link rel="stylesheet" href="/linaria.css" />
<link rel="stylesheet" href="/build/endtoend.css" />
<script type="module" src="/build/endtoend.esm.js"></script>
<script nomodule src="/build/endtoend.js"></script>
</head>
<body>
<app-root></app-root>
</body>
</html>
17 changes: 12 additions & 5 deletions test/end-to-end/stencil.config.ts
@@ -1,12 +1,23 @@
import { Config } from '../../internal';
import builtins from 'rollup-plugin-node-builtins';
import linaria from 'linaria/rollup';
import css from 'rollup-plugin-css-only';
import { reactOutputTarget } from '@stencil/react-output-target';
import path from 'path';

export const config: Config = {
namespace: 'EndToEnd',
globalScript: './src/global.ts',
globalStyle: './src/global.css',
plugins: [builtins()],
rollupPlugins: {
after: [
linaria(),
css({
output: path.join(__dirname, 'www', 'linaria.css'),
}),
],
},

testing: {
moduleNameMapper: {
Expand All @@ -16,6 +27,7 @@ export const config: Config = {
outputTargets: [
{
type: 'www',
empty: false,
serviceWorker: null,
},
{
Expand All @@ -29,11 +41,6 @@ export const config: Config = {
proxiesFile: './dist-react/components.ts',
}),
],
commonjs: {
namedExports: {
'file-saver': ['saveAs'],
},
},
hydratedFlag: {
name: 'custom-hydrate-flag',
selector: 'attribute',
Expand Down

0 comments on commit b5a2536

Please sign in to comment.