Skip to content

Commit 1efb03a

Browse files
authored
Fix @import statements for vue (codesandbox#3459)
* Fix @import statements for vue Fixes codesandbox#3419 * Fix which source is used
1 parent 5f092e1 commit 1efb03a

File tree

7 files changed

+108
-62
lines changed

7 files changed

+108
-62
lines changed

.circleci/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ commands:
151151
steps:
152152
- restore_cache: *restore_deps_cache
153153
- restore_cache: *restore_standalone_deps_cache
154+
# Add extra items to yarnclean so the cache doesn't grow too big
155+
- run:
156+
name: Configure .yarnclean
157+
command: cat .yarnclean.ci >> .yarnclean
154158
- run:
155159
name: Install Dependencies
156160
command: yarn install

.yarnclean

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,3 @@
1-
# test directories
2-
__tests__
3-
test
4-
tests
5-
powered-test
6-
7-
# asset directories
8-
docs
9-
doc
10-
website
11-
images
12-
13-
# examples
14-
example
15-
examples
16-
17-
# code coverage directories
18-
coverage
19-
.nyc_output
20-
21-
# build scripts
22-
Makefile
23-
Gulpfile.js
24-
Gruntfile.js
25-
26-
# configs
27-
appveyor.yml
28-
circle.yml
29-
codeship-services.yml
30-
codeship-steps.yml
31-
wercker.yml
32-
.tern-project
33-
.gitattributes
34-
.editorconfig
35-
.*ignore
36-
.eslintrc
37-
.jshintrc
38-
.flowconfig
39-
.documentup.json
40-
.yarn-metadata.json
41-
.travis.yml
42-
43-
# misc
44-
*.md
45-
461
@types/react-native
472
packages/app/node_modules/styled-components
483

@@ -51,4 +6,4 @@ packages/app/node_modules/styled-components
516
graphql-config/node_modules/**
527

538
# Issue with jest conflicting with jest-styled-components
54-
jest-styled-components/typings/**
9+
jest-styled-components/typings/**

.yarnclean.ci

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# test directories
2+
__tests__
3+
test
4+
tests
5+
powered-test
6+
7+
# asset directories
8+
docs
9+
doc
10+
website
11+
images
12+
13+
# examples
14+
example
15+
examples
16+
17+
# code coverage directories
18+
coverage
19+
.nyc_output
20+
21+
# build scripts
22+
Makefile
23+
Gulpfile.js
24+
Gruntfile.js
25+
26+
# configs
27+
appveyor.yml
28+
circle.yml
29+
codeship-services.yml
30+
codeship-steps.yml
31+
wercker.yml
32+
.tern-project
33+
.gitattributes
34+
.editorconfig
35+
.*ignore
36+
.eslintrc
37+
.jshintrc
38+
.flowconfig
39+
.documentup.json
40+
.yarn-metadata.json
41+
.travis.yml
42+
43+
# misc
44+
*.md

packages/app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"overmind-devtools": "^19.0.0",
166166
"overmind-react": "^23.0.0-1580488381342",
167167
"phoenix": "^1.4.11",
168-
"postcss": "^6.0.9",
168+
"postcss": "^7.0.26",
169169
"postcss-selector-parser": "^2.2.3",
170170
"posthtml": "^0.11.3",
171171
"posthtml-parser": "^0.4.1",
@@ -312,6 +312,7 @@
312312
"path-exists": "3.0.0",
313313
"path-override-webpack-plugin": "^0.1.2",
314314
"postcss-flexbugs-fixes": "^4.1.0",
315+
"postcss-import": "^12.0.1",
315316
"postcss-loader": "3.0.0",
316317
"postcss-normalize": "^8.0.1",
317318
"postcss-preset-env": "^6.7.0",

packages/app/src/sandbox/eval/cache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ export function ignoreNextCache() {
164164

165165
export async function consumeCache(manager: Manager) {
166166
try {
167-
const shouldIgnoreCache = localStorage.getItem('ignoreCache');
167+
const shouldIgnoreCache =
168+
localStorage.getItem('ignoreCache') ||
169+
localStorage.getItem('ignoreCacheDev');
168170
if (shouldIgnoreCache) {
169171
localStorage.removeItem('ignoreCache');
170172

packages/app/src/sandbox/eval/transpilers/vue/style-compiler/loader.js renamed to packages/app/src/sandbox/eval/transpilers/vue/style-compiler/loader.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import postcss from 'postcss';
1+
import postcss, { ProcessOptions } from 'postcss';
2+
import postcssImportPlugin from 'postcss-import';
23

3-
import { type LoaderContext } from '../../../transpiled-module';
4+
import { LoaderContext } from '../../../transpiled-module';
45

56
import trim from './plugins/trim';
67
import scopeId from './plugins/scope-id';
78

8-
export default function(code: string, loaderContext: LoaderContext) {
9+
export default function(
10+
code: string,
11+
loaderContext: LoaderContext
12+
): Promise<{ transpiledCode: string; sourceMap: any }> {
913
return new Promise((resolve, reject) => {
1014
const query = loaderContext.options;
1115

@@ -14,17 +18,35 @@ export default function(code: string, loaderContext: LoaderContext) {
1418
if (!vueOptions) {
1519
vueOptions = {
1620
...loaderContext.options.vue,
17-
...loaderContext.vue,
1821
};
1922
}
2023

2124
// TODO autoprefixer
22-
const plugins = [trim];
25+
const plugins = [
26+
postcssImportPlugin({
27+
resolve: async (id: string) => {
28+
try {
29+
const result = await loaderContext.resolveTranspiledModuleAsync(id);
2330

24-
const options = {
31+
return result.module.path;
32+
} catch (e) {
33+
return null;
34+
}
35+
},
36+
load: async (filename: string) => {
37+
const tModule = await loaderContext.resolveTranspiledModuleAsync(
38+
filename
39+
);
40+
41+
return tModule.module.code;
42+
},
43+
}),
44+
trim,
45+
];
46+
47+
const options: ProcessOptions = {
2548
to: loaderContext.path,
2649
from: loaderContext.path,
27-
map: false,
2850
};
2951

3052
// add plugin for vue-loader scoped css rewrite
@@ -35,13 +57,13 @@ export default function(code: string, loaderContext: LoaderContext) {
3557
// source map
3658
if (
3759
loaderContext.sourceMap &&
38-
vueOptions.cssSourceMap !== false &&
39-
!loaderContext.map
60+
vueOptions.cssSourceMap !== false
61+
// !loaderContext.map
4062
) {
4163
options.map = {
4264
inline: false,
4365
annotation: false,
44-
prev: loaderContext.map,
66+
// prev: loaderContext.map,
4567
};
4668
}
4769

@@ -51,7 +73,8 @@ export default function(code: string, loaderContext: LoaderContext) {
5173
.process(code === null ? undefined : code, options)
5274
.then(result => {
5375
if (result.messages) {
54-
result.messages.forEach(m => {
76+
const messages = result.messages as any[];
77+
messages.forEach(m => {
5578
if (m.type === 'dependency') {
5679
loaderContext.addDependency(m.file);
5780
}

yarn.lock

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22112,6 +22112,16 @@ postcss-image-set-function@^3.0.1:
2211222112
postcss "^7.0.2"
2211322113
postcss-values-parser "^2.0.0"
2211422114

22115+
postcss-import@^12.0.1:
22116+
version "12.0.1"
22117+
resolved "https://registry.yarnpkg.com/postcss-import/-/postcss-import-12.0.1.tgz#cf8c7ab0b5ccab5649024536e565f841928b7153"
22118+
integrity sha512-3Gti33dmCjyKBgimqGxL3vcV8w9+bsHwO5UrBawp796+jdardbcFl4RP5w/76BwNL7aGzpKstIfF9I+kdE8pTw==
22119+
dependencies:
22120+
postcss "^7.0.1"
22121+
postcss-value-parser "^3.2.3"
22122+
read-cache "^1.0.0"
22123+
resolve "^1.1.7"
22124+
2211522125
postcss-initial@^3.0.0:
2211622126
version "3.0.1"
2211722127
resolved "https://registry.yarnpkg.com/postcss-initial/-/postcss-initial-3.0.1.tgz#99d319669a13d6c06ef8e70d852f68cb1b399b61"
@@ -22621,7 +22631,7 @@ postcss-unique-selectors@^4.0.1:
2262122631
postcss "^7.0.0"
2262222632
uniqs "^2.0.0"
2262322633

22624-
postcss-value-parser@^3.0.0, postcss-value-parser@^3.3.0, postcss-value-parser@^3.3.1:
22634+
postcss-value-parser@^3.0.0, postcss-value-parser@^3.2.3, postcss-value-parser@^3.3.0, postcss-value-parser@^3.3.1:
2262522635
version "3.3.1"
2262622636
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz#9ff822547e2893213cf1c30efa51ac5fd1ba8281"
2262722637
integrity sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ==
@@ -22676,15 +22686,15 @@ postcss@^5.2.12, postcss@^5.2.16:
2267622686
source-map "^0.5.6"
2267722687
supports-color "^3.2.3"
2267822688

22679-
postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.23, postcss@^6.0.9:
22689+
postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.23:
2268022690
version "6.0.23"
2268122691
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.23.tgz#61c82cc328ac60e677645f979054eb98bc0e3324"
2268222692
dependencies:
2268322693
chalk "^2.4.1"
2268422694
source-map "^0.6.1"
2268522695
supports-color "^5.4.0"
2268622696

22687-
postcss@^7, postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.11, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.17, postcss@^7.0.2, postcss@^7.0.23, postcss@^7.0.5, postcss@^7.0.6:
22697+
postcss@^7, postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.11, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.17, postcss@^7.0.2, postcss@^7.0.23, postcss@^7.0.26, postcss@^7.0.5, postcss@^7.0.6:
2268822698
version "7.0.26"
2268922699
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.26.tgz#5ed615cfcab35ba9bbb82414a4fa88ea10429587"
2269022700
integrity sha512-IY4oRjpXWYshuTDFxMVkJDtWIk2LhsTlu8bZnbEJA4+bYT16Lvpo8Qv6EvDumhYRgzjZl489pmsY3qVgJQ08nA==
@@ -24372,6 +24382,13 @@ reactcss@^1.2.0:
2437224382
dependencies:
2437324383
lodash "^4.0.1"
2437424384

24385+
read-cache@^1.0.0:
24386+
version "1.0.0"
24387+
resolved "https://registry.yarnpkg.com/read-cache/-/read-cache-1.0.0.tgz#e664ef31161166c9751cdbe8dbcf86b5fb58f774"
24388+
integrity sha1-5mTvMRYRZsl1HNvo28+GtftY93Q=
24389+
dependencies:
24390+
pify "^2.3.0"
24391+
2437524392
read-chunk@^3.0.0:
2437624393
version "3.2.0"
2437724394
resolved "https://registry.yarnpkg.com/read-chunk/-/read-chunk-3.2.0.tgz#2984afe78ca9bfbbdb74b19387bf9e86289c16ca"

0 commit comments

Comments
 (0)