Skip to content

Commit ca115e1

Browse files
kaizhu256lovasoa
andauthored
remove coffeescript dependency and use vanilla .js files (#349)
* run shell command: ```sh # revert individual .coffee files to .js npm install [email protected] for LIB in api-data api exports worker do cat "src/$LIB.coffee" | npx coffee --bare --compile --stdio > "src/$LIB.js" done # restore package-lock.json git checkout package-lock.json ``` * update Makefile to use vanilla src/*.js files instead of src/*.coffee * remove references and dependencies to coffeescript in files: ``` $ git grep -i coffee .github/workflows/CI.yml: - name: install coffee .github/workflows/CI.yml: run: npm install --global coffeescript@1 .github/workflows/release.yml: - name: install coffee .github/workflows/release.yml: run: npm install --global coffeescript@1 .npmignore:coffee/ package-lock.json: "coffeescript": { package-lock.json: "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-1.12.7.tgz", package.json: "coffeescript": "^1.12.7", ``` * remove .coffee files: deleted: src/api-data.coffee deleted: src/api.coffee deleted: src/exports.coffee deleted: src/worker.coffee * simplify ci-build and vanilla-js cleanup by merging following files into api.js, respectively: src/output-pre.js src/api.js src/exports.js src/api-data.js src/output-post.js * rename OUTPUT_API_FILES to SOURCE_API_FILES in Makefile * add file test/jslint.js and npm-command "npm run test-jslint" todo - allow test-jslint to fail after we finish refactoring src/api.js (test-jslint currently always pass) * lint src/api.js - resolve conversation - we need only 1 variable lint src/api.js - resolve conversation - Object.values() lint src/api.js - resolve conversation - we can iterate in increasing order lint src/api.js - resolve conversation - the var could be directly in front of the variables lint src/api.js - resolve conversation - remove merge-comments lint src/api.js - unindent case-statement lint src/api.js - use jslint-style-guide of quoting strings with double-quote instead of single-quote lint src/api.js - hoist constant vars to top of file lint src/api.js - rename property SQlite.xxx to var SQLITE_xxx lint src/api.js - remove var runCompiledCode lint src/api.js - use 4-space indent * jslint src/api.js - replace expression "xxx == null" with "isNullOrUndefined(xxx)" jslint src/api.js - replace expression "void 0" with "undefined" jslint src/api.js - fix warning "Line is longer than 80 characters." jslint src/api.js - fix warning "Undeclared xxx." jslint src/api.js - fix miscellaneous jslint warnings in src/api.js jslint - allow jslint to print all warnings jslint - ignore warning subscript_a * jslint src/api.js - fixed all warnings jslint - "npm test" will now fail if src/api.js fails jslint-check jslint src/api.js - fix whitespace warnings * Add kaizhu256 to the authors * Add more intermediary files to gitignore * Create a single "clean" target * Remove compiled files from the repository * Keep an empty dist/ folder * Switch from jslint to eslint ...and fix all warning and errors * fix a bug I introduced in db.create_function * Finally fix the webworker tests Fixes #180 Co-authored-by: Ophir LOJKINE <[email protected]>
1 parent e902ec2 commit ca115e1

35 files changed

+8230
-953550
lines changed

.eslintrc.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: true,
6+
},
7+
extends: [
8+
'airbnb-base',
9+
],
10+
globals: {
11+
Atomics: 'readonly',
12+
SharedArrayBuffer: 'readonly',
13+
},
14+
parserOptions: {
15+
ecmaVersion: 5,
16+
sourceType: "script",
17+
},
18+
rules: {
19+
"strict": ["error", "function"],
20+
"no-cond-assign": ["error", "except-parens"],
21+
"no-var": "off",
22+
"vars-on-top": "off",
23+
"prefer-destructuring": "off",
24+
"prefer-spread": "off",
25+
"prefer-template": "off",
26+
"prefer-arrow-callback": "off",
27+
"comma-dangle": "off",
28+
"object-shorthand": "off",
29+
"no-throw-literal": "off",
30+
"no-param-reassign": "off",
31+
"no-bitwise": "off",
32+
"camelcase": "off",
33+
"dot-notation": "off",
34+
"indent": ["error", 4],
35+
"quotes": ["error", "double"],
36+
},
37+
};

.github/workflows/CI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010
- uses: mymindstorm/setup-emsdk@v1
1111
with:
1212
version: '1.38.48'
13-
- name: install coffee
14-
run: npm install --global coffeescript@1
1513
- uses: actions/cache@v1
1614
id: cache
1715
with:

.github/workflows/release.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ jobs:
1515
- uses: mymindstorm/setup-emsdk@v1
1616
with:
1717
version: '1.38.48'
18-
- name: install coffee
19-
run: npm install --global coffeescript@1
2018
- name: make
2119
run: make
2220
- name: Create Release
@@ -37,7 +35,7 @@ jobs:
3735
env:
3836
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3937
with:
40-
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
38+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
4139
asset_path: ./sqljs.zip
4240
asset_name: sqljs.zip
4341
asset_content_type: application/zip

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ node_modules/
22
*~
33

44
# Intermediary files:
5+
cache/
56
out/
67
sqlite-src/
7-
cache/
8+
tmp/
9+
c/
10+
emsdk/

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
test/
22
c/
3-
coffee/
43
gh-pages/
54
node_modules/
65
node-debug.log

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Ophir LOJKINE <[email protected]> (https://github.com/lovasoa)
44
@firien
55
@dinedal
66
@taytay
7+
@kaizhu256

Makefile

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc
6262

6363
OUTPUT_WRAPPER_FILES = src/shell-pre.js src/shell-post.js
6464

65-
OUTPUT_API_FILES = out/api.js
65+
SOURCE_API_FILES = src/api.js
6666

6767
EMFLAGS_PRE_JS_FILES = \
68-
--pre-js out/api.js
68+
--pre-js src/api.js
6969

7070
EXPORTED_METHODS_JSON_FILES = src/exported_functions.json src/exported_runtime_methods.json
7171

@@ -74,13 +74,13 @@ all: optimized debug worker
7474
.PHONY: debug
7575
debug: dist/sql-asm-debug.js dist/sql-wasm-debug.js
7676

77-
dist/sql-asm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(OUTPUT_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
77+
dist/sql-asm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
7878
$(EMCC) $(EMFLAGS) $(EMFLAGS_DEBUG) $(EMFLAGS_ASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
7979
mv $@ out/tmp-raw.js
8080
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
8181
rm out/tmp-raw.js
8282

83-
dist/sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(OUTPUT_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
83+
dist/sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
8484
$(EMCC) $(EMFLAGS) $(EMFLAGS_DEBUG) $(EMFLAGS_WASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
8585
mv $@ out/tmp-raw.js
8686
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
@@ -89,19 +89,19 @@ dist/sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(OUTPUT_API_FI
8989
.PHONY: optimized
9090
optimized: dist/sql-asm.js dist/sql-wasm.js dist/sql-asm-memory-growth.js
9191

92-
dist/sql-asm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(OUTPUT_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
92+
dist/sql-asm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
9393
$(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) $(EMFLAGS_ASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
9494
mv $@ out/tmp-raw.js
9595
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
9696
rm out/tmp-raw.js
9797

98-
dist/sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(OUTPUT_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
98+
dist/sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
9999
$(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) $(EMFLAGS_WASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
100100
mv $@ out/tmp-raw.js
101101
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
102102
rm out/tmp-raw.js
103103

104-
dist/sql-asm-memory-growth.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(OUTPUT_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
104+
dist/sql-asm-memory-growth.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
105105
$(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) $(EMFLAGS_ASM_MEMORY_GROWTH) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
106106
mv $@ out/tmp-raw.js
107107
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
@@ -111,64 +111,50 @@ dist/sql-asm-memory-growth.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(OUTPUT
111111
.PHONY: worker
112112
worker: dist/worker.sql-asm.js dist/worker.sql-asm-debug.js dist/worker.sql-wasm.js dist/worker.sql-wasm-debug.js
113113

114-
out/worker.js: src/worker.coffee
115-
cat $^ | npx coffee --bare --compile --stdio > $@
116-
117-
dist/worker.sql-asm.js: dist/sql-asm.js out/worker.js
114+
dist/worker.sql-asm.js: dist/sql-asm.js src/worker.js
118115
cat $^ > $@
119116

120-
dist/worker.sql-asm-debug.js: dist/sql-asm-debug.js out/worker.js
117+
dist/worker.sql-asm-debug.js: dist/sql-asm-debug.js src/worker.js
121118
cat $^ > $@
122119

123-
dist/worker.sql-wasm.js: dist/sql-wasm.js out/worker.js
120+
dist/worker.sql-wasm.js: dist/sql-wasm.js src/worker.js
124121
cat $^ > $@
125122

126-
dist/worker.sql-wasm-debug.js: dist/sql-wasm-debug.js out/worker.js
123+
dist/worker.sql-wasm-debug.js: dist/sql-wasm-debug.js src/worker.js
127124
cat $^ > $@
128125

129126
# Building it this way gets us a wrapper that _knows_ it's in worker mode, which is nice.
130127
# However, since we can't tell emcc that we don't need the wasm generated, and just want the wrapper, we have to pay to have the .wasm generated
131128
# even though we would have already generated it with our sql-wasm.js target above.
132129
# This would be made easier if this is implemented: https://github.com/emscripten-core/emscripten/issues/8506
133-
# dist/worker.sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js out/worker.js $(EXPORTED_METHODS_JSON_FILES) dist/sql-wasm-debug.wasm
134-
# $(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) -s ENVIRONMENT=worker -s $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js out/api.js -o out/sql-wasm.js
130+
# dist/worker.sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) src/api.js src/worker.js $(EXPORTED_METHODS_JSON_FILES) dist/sql-wasm-debug.wasm
131+
# $(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) -s ENVIRONMENT=worker -s $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js src/api.js -o out/sql-wasm.js
135132
# mv out/sql-wasm.js out/tmp-raw.js
136-
# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js out/worker.js > $@
133+
# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js src/worker.js > $@
137134
# #mv out/sql-wasm.wasm dist/sql-wasm.wasm
138135
# rm out/tmp-raw.js
139136

140-
# dist/worker.sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js out/worker.js $(EXPORTED_METHODS_JSON_FILES) dist/sql-wasm-debug.wasm
141-
# $(EMCC) -s ENVIRONMENT=worker $(EMFLAGS) $(EMFLAGS_DEBUG) -s ENVIRONMENT=worker -s WASM_BINARY_FILE=sql-wasm-foo.debug $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js out/api.js -o out/sql-wasm-debug.js
137+
# dist/worker.sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) src/api.js src/worker.js $(EXPORTED_METHODS_JSON_FILES) dist/sql-wasm-debug.wasm
138+
# $(EMCC) -s ENVIRONMENT=worker $(EMFLAGS) $(EMFLAGS_DEBUG) -s ENVIRONMENT=worker -s WASM_BINARY_FILE=sql-wasm-foo.debug $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js src/api.js -o out/sql-wasm-debug.js
142139
# mv out/sql-wasm-debug.js out/tmp-raw.js
143-
# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js out/worker.js > $@
140+
# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js src/worker.js > $@
144141
# #mv out/sql-wasm-debug.wasm dist/sql-wasm-debug.wasm
145142
# rm out/tmp-raw.js
146143

147-
out/api.js: src/output-pre.js src/api.coffee src/exports.coffee src/api-data.coffee src/output-post.js
148-
mkdir -p out
149-
cat src/api.coffee src/exports.coffee src/api-data.coffee | npx coffee --bare --compile --stdio > $@
150-
cat src/output-pre.js $@ src/output-post.js > out/api-wrapped.js
151-
mv out/api-wrapped.js $@
152-
153144
out/sqlite3.bc: sqlite-src/$(SQLITE_AMALGAMATION)
154145
mkdir -p out
155146
# Generate llvm bitcode
156-
$(EMCC) $(CFLAGS) sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@
147+
$(EMCC) $(CFLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@
157148

158149
out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS)
159150
mkdir -p out
160-
$(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@
151+
$(EMCC) $(CFLAGS) -s LINKABLE=1 -c sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@
161152

162153
# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder
163154
# module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js
164155
# tar --create --gzip $^ > $@
165156

166157
## cache
167-
168-
.PHONY: clean-cache
169-
clean-cache:
170-
rm -rf cache
171-
172158
cache/$(SQLITE_AMALGAMATION).zip:
173159
mkdir -p cache
174160
curl -LsSf '$(SQLITE_AMALGAMATION_ZIP_URL)' -o $@
@@ -178,11 +164,6 @@ cache/$(EXTENSION_FUNCTIONS):
178164
curl -LsSf '$(EXTENSION_FUNCTIONS_URL)' -o $@
179165

180166
## sqlite-src
181-
182-
.PHONY: clean-sqlite-src
183-
clean-sqlite-src:
184-
rm -rf sqlite
185-
186167
.PHONY: sqlite-src
187168
sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(EXTENSION_FUNCTIONS)
188169

@@ -203,10 +184,6 @@ sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNC
203184

204185
.PHONY: clean
205186
clean:
206-
rm -rf out/* dist/*
207-
208-
.PHONY: clean-all
209-
clean-all:
210187
rm -f out/* dist/* cache/*
211-
rm -rf sqlite-src/
188+
rm -rf sqlite-src/ c/
212189

dist/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

0 commit comments

Comments
 (0)