You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/buildtools/3-structure.md
+4-12Lines changed: 4 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
1
# General Design of the Build Tools
2
2
3
3
## Path Resolution
4
-
The build tools are designed to be written in Typescript, then compiled and bundled by `esbuild` into a single minified Javascript file `bin/index.js`. This means relative paths used during runtime need to be written in such a way that they account for the path of the executable file.
4
+
The build tools are designed to be written in Typescript, then compiled and bundled by `esbuild` into a single minified Javascript file `dist/index.js`. This means relative paths used during runtime need to be written in such a way that they account for the path of the executable file.
5
5
6
-
For example, the template script needs to copy the templates from the `bin/templates` folder. So the call to `fs.cp` is written relative to `import.meta.dirname` instead of
6
+
For example, the template script needs to copy the templates from the `dist/templates` folder. So the call to `fs.cp` is written relative to `import.meta.dirname` instead of
When `bin/index.js` is executed, `import.meta.dirname` refers to `lib/buildtools/bin`, so the above path becomes `lib/buildtools/bin/templates/bundle`, which is the actual location of where the template files are located.
14
+
When `dist/index.js` is executed, `import.meta.dirname` refers to `lib/buildtools/dist`, so the above path becomes `lib/buildtools/dist/templates/bundle`, which is the actual location of where the template files are located.
15
15
16
16
On the other hand, relative module imports that are bundled during the compilation process don't need to be changed. The template script imports the root package json to
Although the resolved module path refers to a path outside of the buildtools folder, during compilation, `esbuild` actually
28
-
embeds the entire JSON file into `bin/index.js`, thus removing the import altogether:
28
+
embeds the entire JSON file into `dist/index.js`, thus removing the import altogether:
29
29
30
30
```ts
31
31
// ../../package.json
@@ -68,14 +68,6 @@ function rawGetGitRoot() {
68
68
```
69
69
This is guaranteed to work, since the user should have Git present on their system (otherwise how did they get this git repo?)
70
70
71
-
Since the path of the git repository shouldn't be changing during execution of the buildtools, we use `lodash`'s [`memoize`](https://lodash.com/docs/4.17.15#memoize) to eliminate unnecessary calls to Git:
72
-
```ts
73
-
/**
74
-
* Get the path to the root of the git repository
75
-
*/
76
-
exportconst getGitRoot =memoize(rawGetGitRoot);
77
-
```
78
-
79
71
By abstracting this functionality into a separate module, it is simple to change the paths at which everything is defined (such as where the directory containing bundles is found). In particular,
80
72
by mocking this module, we can run the buildtools on mock bundles and tabs with ease.
0 commit comments