-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
229 lines (169 loc) · 8.23 KB
/
index.html
File metadata and controls
229 lines (169 loc) · 8.23 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="generator" content="Hugo 0.17" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>logspace</title>
<link rel="stylesheet" href="http://logspace.co.uk/css/poole.css">
<link rel="stylesheet" href="http://logspace.co.uk/css/syntax.css">
<link rel="stylesheet" href="http://logspace.co.uk/css/hyde.css">
<link href="https://fonts.googleapis.com/css?family=Berkshire+Swash|Crimson+Text" rel="stylesheet">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="http://logspace.co.uk/apple-touch-icon-144-precomposed.png">
<link rel="shortcut icon" href="http://logspace.co.uk/favicon.png">
<link href="http://logspace.co.uk/index.xml" rel="alternate" type="application/rss+xml" title="logspace" />
</head>
<body class="theme-base-0f layout-reverse">
<div class="sidebar">
<div class="container sidebar-sticky">
<div class="sidebar-about">
<a href="http://logspace.co.uk/"><h1>logspace</h1></a>
<p class="lead">
data / code / science by Ben Blackburne
</p>
</div>
<ul class="sidebar-nav">
<li><a href="http://logspace.co.uk/">Home</a> </li>
<li><a href="http://logspace.co.uk/page/about/"> About </a></li>
<li><a href="http://logspace.co.uk/page/publications/"> Publications </a></li>
</ul>
<p> </p>
</div>
</div>
<div class="content container">
<div class="posts">
<div class="post">
<h1 class="post-title">
<a href="http://logspace.co.uk/post/alias-resolver/">
Dealing with macOS aliases on the command-line
</a>
</h1>
<span class="post-date">Thu, Jan 12, 2017</span>
<p>If you’ve been using a Mac for a while, you’ve probably come up against
<a href="https://en.wikipedia.org/wiki/Alias_(Mac_OS)">Aliases</a>. They’re similar in
many ways to the Unix <a href="https://en.wikipedia.org/wiki/Symbolic_link">Symbolic
Link</a>, but have their own set of
advantages and disadvantages. The main advantage is you can move the original
file to a new location on the same disk, and the alias will still find it. The
main disadvantage (for me) is that the OS X Unix layer doesn’t know what to do
with them.</p>
<p>We use aliases in <a href="http://papersapp.com">Papers</a> for various reasons, and I
needed a way to handle them from the node.js world. For that reason, I wrote a
small module called <a href="https://www.npmjs.com/package/alias-resolver">Alias
Resolver</a>. I recently updated the
module to support the creation of aliases (mainly because it is useful for
testing). As a side-effect of this, the module is now usable for creating and
resolving aliases on the command-line.</p>
<p>To create an alias in the shell, you may have used some <a href="http://stackoverflow.com/questions/7072208/how-do-i-create-a-macintosh-finder-alias-from-the-command-line">funky-looking
AppleScript</a>
to tell the Finder to do it for you. Now, it’s much simpler (assuming you have
<a href="http://brew.sh">Homebrew</a> or Node.js), as Alias Resolver comes with the
<code>create-alias</code> and <code>resolve-alias</code> commands.</p>
<pre><code> $ brew install node
$ npm install -g alias-resolver
$ create-alias /bin/ls /tmp/ls-alias
$ file /tmp/ls-alias
/tmp/ls-alias: MacOS Alias file
$ cat /tmp/ls-alias
bookmark88<'Atbinv8A file:///
Macintosh H(A&$FE16297F-ACA3-31D2-88EF-3B67691353C9/0dnib(Xx@h ( 0 4"<%
$ resolve-alias /tmp/ls-alias
/bin/ls
</code></pre>
</div>
<div class="post">
<h1 class="post-title">
<a href="http://logspace.co.uk/post/typescript-module/">
Creating an NPM module in TypeScript
</a>
</h1>
<span class="post-date">Mon, Oct 10, 2016</span>
<p>I’m a great believer in type systems and we’ve recently started to use
TypeScript. We want to mix TypeScript modules into our existing node.js code.
However, TypeScript is a rapidly changing ecosystem, which meant I went down
some blind alleys when trying to figure out how to set up an npm module.
It turns out, with TypeScript 2.0, it’s really simple. Here’s one suggestion
for how to get started. Begin with a directory for your project and</p>
<pre><code>npm init
</code></pre>
<p>Set your entry point to <code>dist/${projectName}.js</code>. For instance, for a project called safeLeftPad, put this in package.json:</p>
<pre><code>{
…
"main": "dist/safeLeftPad.js",
…
}
</code></pre>
<p>You’re going to need to install TypeScript if you haven’t already. Let’s
install it globally, and in the project so random JavaScript hackers can still
compile our module.</p>
<pre><code>npm install --save-dev typescript
npm install --global typescript
</code></pre>
<p>Typescript uses a <code>tsconfig.json</code> file to configure the compiler. Let’s autogenerate one:</p>
<pre><code>tsc --init
</code></pre>
<p>You need to edit it to output to the correct directory (<code>dist</code>) and set the
source location. You only need to point it at the main entry point file. I also
turn on <code>noImplicitAny</code> to keep me honest, and target es6 to get the cool
stuff. My <code>tsconfig.json</code> now looks like this:</p>
<pre><code>{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"sourceMap": false,
"outDir": "dist"
},
"files": [
"src/safeLeftPad.ts"
]
}
</code></pre>
<p>Add <code>tsc</code> as a prepublish command to <code>package.json</code> so the TypeScript is compiled when you
package. My <code>package.json</code> now looks like this:</p>
<pre><code>{
"name": "safe-left-pad",
"version": "0.0.1",
"description": "",
"main": "dist/safeLeftPad.js",
"scripts": {
"prepublish": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Ben Blackburne",
"license": "ISC",
"devDependencies": {
"typescript": "^2.0.3"
}
}
</code></pre>
<p>To compile your TypeScript, simply run <code>tsc</code> and the appropriate <code>.js</code> and
<code>.d.ts</code> files are created in <code>dist/</code>. You don’t need <code>autodts</code>.</p>
<h2 id="a-word-about-typings">A word about typings</h2>
<p>The first thing you are probably going to do is try and use some node modules.
To do so, you need the appropriate Declaration Files for the module, which
contain the type definitions. There’s a bunch of pre-existing projects for this
(e.g. <code>typings</code>, DefinitelyTyped). However, it is now all integrated into <code>npm</code>
and you need (in theory) do nothing more than <code>npm install @types/${moduleName}</code>.
I’ve come across a couple of gotchas though.</p>
<p>Firstly, the type definitions won’t necessarily match the module version, and
<code>npm</code> won’t care. For instance:</p>
<pre><code>npm install request-promise @types/request-promise --save
</code></pre>
<p>At time of writing, this will happily install request-types version 4, and the
definitions for version 3. In this case, I suggest you manually use the older version of <code>request-promise</code>:</p>
<pre><code>npm install request-promise@3.0.0 @types/request-promise@3.0.0 --save
</code></pre>
<p>Secondly, it doesn’t seem to handle dependencies well. On compiling a project,
you may find an error about missing dependencies:</p>
<pre><code>node_modules/@types/request-promise/index.d.ts(10,30): error TS2307: Cannot find module 'bluebird'.
</code></pre>
<p>So you have to manually install the missing definitions:</p>
<pre><code>npm install @types/bluebird --save
</code></pre>
</div>
</div>
</div>
</body>
</html>