File tree 5 files changed +70
-24
lines changed
src/shared/svelte-compile-warns/transform
5 files changed +70
-24
lines changed Original file line number Diff line number Diff line change @@ -18,5 +18,9 @@ module.exports = {
18
18
// eslint-disable-next-line no-process-env -- ignore
19
19
process . env . NODE_OPTIONS || ''
20
20
} `
21
+ } ,
22
+ test : {
23
+ SYNCKIT_TIMEOUT : 1000 ,
24
+ SYNCKIT_TS_RUNNER : 'esbuild-register'
21
25
}
22
26
} ;
Original file line number Diff line number Diff line change 47
47
"prerelease" : " pnpm run clean && pnpm run build" ,
48
48
"release" : " changeset publish" ,
49
49
"svelte-kit" : " env-cmd -e sveltekit node node_modules/vite/bin/vite.js" ,
50
- "test" : " pnpm run mocha \" tests/src/**/*.ts\" --reporter dot --timeout 60000" ,
50
+ "test" : " env-cmd -e test pnpm run mocha \" tests/src/**/*.ts\" --reporter dot --timeout 60000" ,
51
51
"test:debug" : " env-cmd -e debug pnpm run test" ,
52
52
"test:update-fixtures" : " env-cmd -e update-fixtures pnpm run test" ,
53
53
"ts" : " node -r esbuild-register" ,
73
73
"esutils" : " ^2.0.3" ,
74
74
"known-css-properties" : " ^0.29.0" ,
75
75
"postcss" : " ^8.4.5" ,
76
- "postcss-load-config" : " ^3.1.4 " ,
76
+ "postcss-load-config" : " ^5.0.2 " ,
77
77
"postcss-safe-parser" : " ^6.0.0" ,
78
78
"postcss-selector-parser" : " ^6.0.11" ,
79
79
"semver" : " ^7.5.3" ,
80
- "svelte-eslint-parser" : " >=0.34.0-next.4 <1.0.0"
80
+ "svelte-eslint-parser" : " >=0.34.0-next.4 <1.0.0" ,
81
+ "synckit" : " ^0.9.0"
81
82
},
82
83
"devDependencies" : {
83
84
"@1stg/browserslist-config" : " ^2.0.0" ,
Original file line number Diff line number Diff line change 1
1
import type { AST } from 'svelte-eslint-parser' ;
2
- import postcss from 'postcss ' ;
3
- import postcssLoadConfig from 'postcss-load-config' ;
2
+ import { createSyncFn } from 'synckit ' ;
3
+
4
4
import type { RuleContext } from '../../../types' ;
5
- import type { TransformResult } from './types' ;
6
5
import { getCwd , getFilename } from '../../../utils/compat' ;
6
+ import type { TransformResult } from './types' ;
7
+
8
+ const postcssProcess = createSyncFn ( require . resolve ( './postcss.worker' ) ) as ( options : {
9
+ cwd : string ;
10
+ filename : string ;
11
+ code : string ;
12
+ configFilePath ?: unknown ;
13
+ } ) => {
14
+ output : string ;
15
+ mappings : string ;
16
+ } ;
7
17
8
18
/**
9
19
* Transform with postcss
@@ -24,33 +34,24 @@ export function transform(
24
34
inputRange = [ node . startTag . range [ 1 ] , node . range [ 1 ] ] ;
25
35
}
26
36
const code = text . slice ( ...inputRange ) ;
27
-
28
37
const filename = `${ getFilename ( context ) } .css` ;
38
+
29
39
try {
30
40
const configFilePath = postcssConfig ?. configFilePath ;
31
41
32
- const config = postcssLoadConfig . sync (
33
- {
34
- cwd : getCwd ( context ) ,
35
- from : filename
36
- } ,
37
- typeof configFilePath === 'string' ? configFilePath : undefined
38
- ) ;
39
-
40
- const result = postcss ( config . plugins ) . process ( code , {
41
- ...config . options ,
42
- map : {
43
- inline : false
44
- }
42
+ const result = postcssProcess ( {
43
+ cwd : getCwd ( context ) ,
44
+ filename,
45
+ code,
46
+ configFilePath
45
47
} ) ;
46
48
47
49
return {
48
50
inputRange,
49
- output : result . content ,
50
- mappings : result . map . toJSON ( ) . mappings
51
+ ...result
51
52
} ;
52
53
} catch ( _e ) {
53
- // console.log(e)
54
+ console . error ( _e ) ;
54
55
return null ;
55
56
}
56
57
}
Original file line number Diff line number Diff line change
1
+ import postcss from 'postcss' ;
2
+ import postcssLoadConfig from 'postcss-load-config' ;
3
+ import { runAsWorker } from 'synckit' ;
4
+
5
+ runAsWorker (
6
+ async ( {
7
+ cwd,
8
+ filename,
9
+ code,
10
+ configFilePath
11
+ } : {
12
+ cwd : string ;
13
+ filename : string ;
14
+ code : string ;
15
+ configFilePath ?: unknown ;
16
+ } ) : Promise < {
17
+ output : string ;
18
+ mappings : string ;
19
+ } > => {
20
+ const config = await postcssLoadConfig (
21
+ {
22
+ cwd,
23
+ from : filename
24
+ } ,
25
+ typeof configFilePath === 'string' ? configFilePath : undefined
26
+ ) ;
27
+
28
+ const result = await postcss ( config . plugins ) . process ( code , {
29
+ ...config . options ,
30
+ map : {
31
+ inline : false
32
+ }
33
+ } ) ;
34
+
35
+ return {
36
+ output : result . content ,
37
+ mappings : result . map . toJSON ( ) . mappings
38
+ } ;
39
+ }
40
+ ) ;
Original file line number Diff line number Diff line change 2
2
"compilerOptions" : {
3
3
"target" : " es2020" ,
4
4
"module" : " commonjs" ,
5
- "moduleResolution" : " Node16 " ,
5
+ "moduleResolution" : " Node10 " ,
6
6
"lib" : [" es2020" , " dom" ],
7
7
"allowJs" : true ,
8
8
"checkJs" : true ,
You can’t perform that action at this time.
0 commit comments