File size: 3,093 Bytes
0ad74ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
diff --git a/src/cli.js b/src/cli.js
index 4833dc489359f2fba202668672f3cd8e09c427d5..7aa312f3677b73dbdfd4d0f1bb2b66bd17346cb3 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -28,9 +28,10 @@ prog
 		'--tsconfig',
 		'A path to a tsconfig or jsconfig file. When not provided, searches for the next upper tsconfig/jsconfig in the workspace path.'
 	)
+	.option('-c, --cwd', 'The current working directory')
 	.action(async (args) => {
 		try {
-			const config = await load_config();
+			const config = await load_config({cwd: args.cwd});
 
 			// @ts-expect-error
 			if (config.package) {
diff --git a/src/index.js b/src/index.js
index a6cbda297cbb23329ceb669942fdba0e7e1c274c..1e813b042739f565829bed56347a44e9c62121eb 100644
--- a/src/index.js
+++ b/src/index.js
@@ -28,27 +28,47 @@ async function do_build(options, analyse_code) {
 		throw new Error(`${path.relative('.', input)} does not exist`);
 	}
 
+	const tmp_input = path.join(input, 'tmp_input')
+
 	rimraf(temp);
+	rimraf(tmp_input)
 	mkdirp(temp);
-
-	const files = scan(input, extensions);
+	mkdirp(tmp_input)
+	copy(input, tmp_input, {
+		filter: (p) => 
+			!p.includes('node_modules') && 
+			!p.includes('dist') && 
+			!p.includes('tmp_input') && 
+			!p.includes('public') &&
+			!p.endsWith('.stories.svelte') && 
+			!p.endsWith('.test.ts') && 
+			!p.endsWith('.spec.ts') && 
+			!p.endsWith('.md') &&
+			!p.endsWith('package.json') &&
+			!p.endsWith('.gitignore') &&
+			!p.endsWith('.svelte-kit')
+	})
+
+	const files = scan(tmp_input, extensions);
 
 	if (options.types) {
-		await emit_dts(input, temp, options.cwd, alias, files);
+		await emit_dts(tmp_input, temp, options.cwd, alias, files);
 	}
 
 	for (const file of files) {
-		await process_file(input, temp, file, options.config.preprocess, alias, tsconfig, analyse_code);
+		await process_file(tmp_input, temp, file, options.config.preprocess, alias, tsconfig, analyse_code);
 	}
 
 	rimraf(output);
 	mkdirp(output);
 	copy(temp, output);
+	rimraf(path.join(temp, ".."))
+	rimraf(tmp_input)
 
 	console.log(
 		colors
 			.bold()
-			.green(`${path.relative(options.cwd, input)} -> ${path.relative(options.cwd, output)}`)
+			.green(`${path.relative(path.join(options.cwd, "..", ".."), input)} -> ${path.relative(options.cwd, output)}`)
 	);
 }
 
diff --git a/src/typescript.js b/src/typescript.js
index 810871d5015257f05199192ed275f051492ca923..53d3c2516086cca5285858c6113a81d885dfebdc 100644
--- a/src/typescript.js
+++ b/src/typescript.js
@@ -20,6 +20,7 @@ import { load_pkg_json } from './config.js';
  */
 export async function emit_dts(input, output, cwd, alias, files) {
 	const tmp = `${output}/__package_types_tmp__`;
+	const root = path.resolve(cwd, "..", "..")
 	rimraf(tmp);
 	mkdirp(tmp);
 
@@ -32,7 +33,7 @@ export async function emit_dts(input, output, cwd, alias, files) {
 		svelteShimsPath: no_svelte_3
 			? require.resolve('svelte2tsx/svelte-shims-v4.d.ts')
 			: require.resolve('svelte2tsx/svelte-shims.d.ts'),
-		declarationDir: path.relative(cwd, tmp)
+		declarationDir: path.relative(root, tmp)
 	});
 
 	const handwritten = new Set();