Skip to content

Commit 70fa333

Browse files
committed
Improve DEMO site
1 parent 85f0a00 commit 70fa333

File tree

9 files changed

+56
-8
lines changed

9 files changed

+56
-8
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = {
2626
"no-lonely-if": "off",
2727
"new-cap": "off",
2828
"no-shadow": "off",
29+
"no-void": ["error", { allowAsStatement: true }],
2930
"prettier/prettier": [
3031
"error",
3132
{},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
export let process = {
22
env: {},
33
cwd: () => "",
4+
stdout: {},
5+
}
6+
if (typeof window !== "undefined") {
7+
window.process = process
48
}

docs-svelte-kit/shim/fs.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* eslint require-jsdoc:0 -- shim */
2+
3+
export {}
4+
export default {}

docs-svelte-kit/shim/globby.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* eslint require-jsdoc:0 -- shim */
2+
3+
export {}
4+
export default {}

docs-svelte-kit/shim/path.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ function resolve(s) {
1616
return s
1717
}
1818

19+
function isAbsolute() {
20+
return false
21+
}
22+
23+
function join(...args) {
24+
return args.join("/")
25+
}
26+
1927
const sep = "/"
2028

21-
const posix = { dirname, extname, resolve, relative, sep }
29+
const posix = { dirname, extname, resolve, relative, sep, isAbsolute, join }
2230
posix.posix = posix
23-
export { dirname, extname, posix, resolve, relative, sep }
31+
export { dirname, extname, posix, resolve, relative, sep, isAbsolute, join }
2432
export default posix

docs-svelte-kit/src/lib/components/ESLintPlayground.svelte

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@
99
preprocess,
1010
postprocess,
1111
} from "../eslint/scripts/linter.js"
12-
13-
const linter = createLinter()
12+
import { loadModulesForBrowser } from "../../../../src/shared/svelte-compile-warns/transform/load-module"
13+
const linter = loadModulesForBrowser()
14+
.then(async () => {
15+
const parser = await import("@typescript-eslint/parser")
16+
if (typeof window !== "undefined") {
17+
window.require.define("@typescript-eslint/parser", parser)
18+
}
19+
})
20+
.then(() => {
21+
return createLinter()
22+
})
1423
1524
const DEFAULT_CODE =
1625
`<!-- Welcome to @ota-meshi/eslint-plugin-svelte -->
@@ -161,6 +170,10 @@
161170
parserOptions: {
162171
ecmaVersion: 2020,
163172
sourceType: "module",
173+
parser: {
174+
ts: "@typescript-eslint/parser",
175+
typescript: "@typescript-eslint/parser",
176+
},
164177
},
165178
rules,
166179
env: {

docs-svelte-kit/src/lib/eslint/ESLintEditor.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
/** message to marker */
8383
async function messageToMarker(message, messageMap) {
8484
const monaco = await loadMonacoEditor()
85-
const rule = message.ruleId && linter.getRules().get(message.ruleId)
85+
const rule = message.ruleId && (await linter).getRules().get(message.ruleId)
8686
const docUrl = rule && rule.meta && rule.meta.docs && rule.meta.docs.url
8787
const startLineNumber = ensurePositiveInt(message.line, 1)
8888
const startColumn = ensurePositiveInt(message.column, 1)

src/shared/svelte-compile-warns/transform/load-module.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { AST } from "svelte-eslint-parser"
22
import Module from "module"
33
import path from "path"
44
import type { RuleContext } from "../../../types"
5-
const cache = new WeakMap<AST.SvelteProgram, Record<string, any>>()
5+
const cache = new WeakMap<AST.SvelteProgram, Record<string, unknown>>()
6+
const cache4b = new Map<string, unknown>()
67
/**
78
* Load module
89
*/
@@ -13,8 +14,8 @@ export function loadModule<R>(context: RuleContext, name: string): R | null {
1314
modules = {}
1415
cache.set(key, modules)
1516
}
16-
const mod = modules[name]
17-
if (mod) return mod
17+
const mod = modules[name] || cache4b.get(name)
18+
if (mod) return mod as R
1819
try {
1920
const createRequire: (filename: string) => (modName: string) => unknown =
2021
// Added in v12.2.0
@@ -30,3 +31,13 @@ export function loadModule<R>(context: RuleContext, name: string): R | null {
3031
return null
3132
}
3233
}
34+
35+
/** Load modules for browser */
36+
export async function loadModulesForBrowser(): Promise<void> {
37+
const [sass, typescript] = await Promise.all([
38+
import("sass"),
39+
import("typescript"),
40+
])
41+
cache4b.set("sass", sass)
42+
cache4b.set("typescript", typescript)
43+
}

svelte.config.esm.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const config = {
6262
path: path.join(dirname, "./docs-svelte-kit/shim/path.mjs"),
6363
url: path.join(dirname, "./docs-svelte-kit/shim/url.mjs"),
6464
os: path.join(dirname, "./docs-svelte-kit/shim/os.mjs"),
65+
fs: path.join(dirname, "./docs-svelte-kit/shim/fs.mjs"),
66+
globby: path.join(dirname, "./docs-svelte-kit/shim/globby.mjs"),
67+
tslib: path.join(dirname, "./node_modules/tslib/tslib.es6.js"),
6568
},
6669
},
6770
plugins: [

0 commit comments

Comments
 (0)