Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit d3a747e

Browse files
committed
Remove the fs dependency in the TS build.
This should allow users who import dist/parser/stage-2-ast to not make their compiler freak out. Before: - Have a grammar/liquid-html.ohm.js that reads liquid-html.ohm with fs - Have a build/shims/liquid-html.ohm file that replaces the fs.readFile with the contents of the file - Have a webpack alias that changes ../../grammar/liquid-html.ohm.js with the shim After: - Have a build script that pastes the content of grammar/liquid-html.ohm into grammar/liquid-html.ohm.js as a module.exports = String.raw``; - Run that script before building - Run that script before running tests The advantage now is that there's no fs dependency in the TS build.
1 parent 441f15c commit d3a747e

File tree

7 files changed

+9
-19
lines changed

7 files changed

+9
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ yarn-error.log
44
.DS_Store
55
dawn
66
TODO
7-
build/shims/liquid-html-ohm.js
7+
grammar/liquid-html.ohm.js
88
standalone.js
99
standalone.js.LICENSE.txt
1010
**/actual.liquid

.mocharc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"require": ["ts-node/register/transpile-only", "tsconfig-paths/register"],
2+
"require": ["./build/shims", "ts-node/register/transpile-only", "tsconfig-paths/register"],
33
"reporter": "spec"
44
}

build/shims.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
const fs = require('fs');
22
const path = require('path');
33

4+
const grammarPath = path.join(__dirname, '../grammar');
5+
46
fs.writeFileSync(
5-
path.join(__dirname, 'shims/liquid-html-ohm.js'),
7+
path.join(grammarPath, 'liquid-html.ohm.js'),
68
'module.exports = ' +
79
'String.raw`' +
8-
require('../grammar/liquid-html.ohm.js').replace(/`/g, '${"`"}') +
10+
fs
11+
.readFileSync(path.join(grammarPath, 'liquid-html.ohm'), 'utf8')
12+
.replace(/`/g, '${"`"}') +
913
'`;',
1014
'utf8',
1115
);

build/shims/.gitkeep

Whitespace-only changes.

grammar/liquid-html.ohm.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"ThirdPartyNotices.txt"
2626
],
2727
"scripts": {
28-
"build": "yarn build:ts && yarn build:shims && yarn build:standalone",
28+
"build": "yarn build:shims && yarn build:ts && yarn build:standalone",
2929
"build:shims": "node build/shims.js",
3030
"build:standalone": "webpack -c webpack.config.js",
3131
"build:ts": "tsc -p . && tsc-alias -p tsconfig.json",

webpack.config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ module.exports = {
2222
root: 'prettier',
2323
},
2424
},
25-
resolve: {
26-
alias: {
27-
'../../grammar/liquid-html.ohm.js': path.resolve(
28-
__dirname,
29-
'build/shims/liquid-html-ohm.js',
30-
),
31-
},
32-
},
3325
optimization: {
3426
minimize: PRODUCTION ? true : false,
3527
},

0 commit comments

Comments
 (0)