]> git.wincent.com - wincent.git/commitdiff
refactor(fig): set up path alias for "fig" -> "src"
authorGreg Hurrell <greg@hurrell.net>
Tue, 21 Apr 2020 22:13:19 +0000 (00:13 +0200)
committerGreg Hurrell <greg@hurrell.net>
Tue, 21 Apr 2020 22:13:19 +0000 (00:13 +0200)
This enables `tsc` to find modules from aspects like so:

    import '../../src/something.js';

instead of:

    import 'fig/something.js';

Normally I hate this kind of path hacking and aliasing because it
obfuscates where things really are.

But in this case aspects are supposed to be a DSL and somehow special.
"gd" in Vim still takes you to the right file (ie. via the LSP server).
Note that "gf" doesn't work after this change, and it didn't work before
it either, because when you are looking at "something.js", you actually
want to go to the source, which is "something.ts". So, "gd" works, but
"gf" doesn't.

aspects/dotfiles/index.ts
aspects/launchd/index.ts
aspects/meta/index.ts
aspects/terminfo/index.ts
aspects/vim/index.ts
install
src/path.ts
tsconfig.json
variables.ts

index 5acda5698286e24a961a56bc6f47e0997b0eaa33..f5a6a2152117a4c6490bec27be2a67cbbb3cc9d6 100644 (file)
@@ -6,9 +6,9 @@ import {
     task,
     variable,
     variables,
-} from '../../src/Fig.js';
-import stat from '../../src/fs/stat.js';
-import path from '../../src/path.js';
+} from 'fig/Fig.js';
+import stat from 'fig/fs/stat.js';
+import path from 'fig/path.js';
 
 variables(({identity}) => ({
     gitUserEmail: identity === 'wincent' ? 'greg@hurrell.net' : '',
index a02e508ff512caf6b6f9330dba6a93087194810d..fd86a20b9515478a7ee7f9e361a0579bd675bc05 100644 (file)
@@ -1,4 +1,4 @@
-import {resource, template, task} from '../../src/Fig.js';
+import {resource, template, task} from 'fig/Fig.js';
 
 task('configure (global) LaunchDaemons', async () => {
     const items = [
index e148ec1907bb29d24c64087d6c58b3595b6cd9f9..6302aca4cb183416c4eb544291538f24f826f915 100644 (file)
@@ -1,13 +1,13 @@
 import {equal, ok} from 'assert';
 import {join} from 'path';
 
-import {file, resource, task, template} from '../../src/Fig.js';
-import Context from '../../src/Fig/Context.js';
-import assert from '../../src/assert.js';
-import {promises} from '../../src/fs.js';
-import stat from '../../src/fs/stat.js';
-import tempdir from '../../src/fs/tempdir.js';
-import {default as toPath} from '../../src/path.js';
+import {file, resource, task, template} from 'fig/Fig.js';
+import Context from 'fig/Fig/Context.js';
+import assert from 'fig/assert.js';
+import {promises} from 'fig/fs.js';
+import stat from 'fig/fs/stat.js';
+import tempdir from 'fig/fs/tempdir.js';
+import {default as toPath} from 'fig/path.js';
 
 function live() {
     return !Context.currentOptions?.check;
index a9332c47ad4ef2608117d316a6ac1a95ae3f86ce..a32e545cb7e0bb2ed496921cf531ff7fc21b9a3c 100644 (file)
@@ -1,4 +1,4 @@
-import {command, file, resource, task, variable} from '../../src/Fig.js';
+import {command, file, resource, task, variable} from 'fig/Fig.js';
 
 task('create target directory', async () => {
     await file({
index b8b4d7896d5ff8a254a940fb1dc8d5508ee2e295..185e67b3bc292d6fa7fbcfd3892d27d7165d4405 100644 (file)
@@ -6,9 +6,9 @@ import {
     skip,
     task,
     variable,
-} from '../../src/Fig.js';
-import stat from '../../src/fs/stat.js';
-import path from '../../src/path.js';
+} from 'fig/Fig.js'; // TODO: obviously need to rename this
+import stat from 'fig/fs/stat.js';
+import path from 'fig/path.js';
 
 task('make directories', async () => {
     // Some overlap with "dotfiles" aspect here.
diff --git a/install b/install
index 065706c4f165209a6c211e9fc89057ae936d12b8..6ecf0646f5e23551b6173f43dd75e992fe673a99 100755 (executable)
--- a/install
+++ b/install
@@ -12,6 +12,9 @@ log_info "Installing TypeScript"
 
 yarn --frozen-lockfile --no-default-rc --no-progress --silent
 
+# TODO: may not need this with Yarn workspaces
+(cd node_modules && ln -s ../lib/src fig)
+
 log_info "Cleaning"
 
 git clean -fq -- lib
index 515d63f2fe3d528505ecf780a5e7ace64db4db58..43f407e15c0e3a6e6d26327bbaf8fbe2e88ff515 100644 (file)
@@ -8,10 +8,6 @@ const inspect = Symbol.for('nodejs.util.inspect.custom');
 
 // TODO: export path module wrappers as well, then I can just use it as a
 // drop-in replacement
-// TODO: decide whether this whole thing is an utterly terrible idea or not
-// (can't do strict-equality comparisons with string-likes)
-//
-// Maybe a full-blown Path object (ie. not a string) would be better.
 
 export type Path = string & {
     basename: Path;
index 0571f9942948663075857caec8ca225c43a34ee4..5faf64fda4c95c5bcbe32e86d6a91df796844da9 100644 (file)
@@ -7,6 +7,10 @@
         "noUnusedLocals": true,
         "noUnusedParameters": true,
         "outDir": "./lib",
+        "baseUrl": ".",
+        "paths": {
+            "fig/*": ["src/*"]
+        },
         "strict": true,
         "target": "ES2019"
     },
index e21331a8c0ffdc3d4a5a06ceab366964aebee29d..85c3985abce9ee12b0141b5943cfd51d2218806c 100644 (file)
@@ -1,4 +1,4 @@
-import Context from './src/Fig/Context.js';
+import Context from 'fig/Fig/Context.js';
 
 /**
  * @file