Skip to content

Commit a4fd90a

Browse files
authored
feat(js): add typescript to the js template (algolia/create-instantsearch-app#464)
* feat(js): add typescript to the js template based on the (for now) not exported as TS https://github.com/algolia/instantsearch.js/blob/master/src/index.ts * update import method * correct file
1 parent 23d5d3e commit a4fd90a

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

e2e/__snapshots__/templates.test.js.snap

+39-2
Original file line numberDiff line numberDiff line change
@@ -3130,7 +3130,7 @@ exports[`Templates InstantSearch.js File content: index.html 1`] = `
31303130
<div id=\\"pagination\\"></div>
31313131
</div>
31323132
3133-
<script src=\\"https://cdn.jsdelivr.net/algoliasearch/3.32.0/algoliasearchLite.min.js\\"></script>
3133+
<script src=\\"https://cdn.jsdelivr.net/algoliasearch/4.10.4/algoliasearchLite.min.js\\"></script>
31343134
<script src=\\"https://cdn.jsdelivr.net/npm/[email protected]\\"></script>
31353135
<script src=\\"./src/app.js\\"></script>
31363136
</body>
@@ -3168,7 +3168,9 @@ exports[`Templates InstantSearch.js File content: package.json 1`] = `
31683168
\\"lint\\": \\"eslint .\\",
31693169
\\"lint:fix\\": \\"npm run lint -- --fix\\"
31703170
},
3171-
\\"partialDependencies\\": {}
3171+
\\"partialDependencies\\": {
3172+
\\"instantsearch.js\\": \\"3.0.0\\"
3173+
}
31723174
}"
31733175
`;
31743176
@@ -3277,6 +3279,18 @@ search.addWidgets([
32773279
search.start();"
32783280
`;
32793281
3282+
exports[`Templates InstantSearch.js File content: src/global.d.ts 1`] = `
3283+
"import algoliasearch from 'algoliasearch/lite';
3284+
import instantsearch from 'instantsearch.js/dist/instantsearch.production.min';
3285+
3286+
declare global {
3287+
interface Window {
3288+
algoliasearch: typeof algoliasearch;
3289+
instantsearch: typeof instantsearch;
3290+
}
3291+
}"
3292+
`;
3293+
32803294
exports[`Templates InstantSearch.js File content: src/index.css 1`] = `
32813295
"body,
32823296
h1 {
@@ -3290,6 +3304,27 @@ body {
32903304
}"
32913305
`;
32923306
3307+
exports[`Templates InstantSearch.js File content: tsconfig.json 1`] = `
3308+
"{
3309+
\\"compilerOptions\\": {
3310+
\\"module\\": \\"commonjs\\",
3311+
\\"esModuleInterop\\": true,
3312+
\\"sourceMap\\": true,
3313+
\\"allowJs\\": true,
3314+
\\"lib\\": [
3315+
\\"es6\\",
3316+
\\"dom\\"
3317+
],
3318+
\\"rootDir\\": \\"src\\",
3319+
\\"moduleResolution\\": \\"node\\"
3320+
},
3321+
\\"include\\": [
3322+
\\"src\\",
3323+
\\"src/global.d.ts\\"
3324+
]
3325+
}"
3326+
`;
3327+
32933328
exports[`Templates InstantSearch.js Folder structure: contains the right files 1`] = `
32943329
Array [
32953330
".editorconfig",
@@ -3304,7 +3339,9 @@ Array [
33043339
"package.json",
33053340
"src/app.css",
33063341
"src/app.js",
3342+
"src/global.d.ts",
33073343
"src/index.css",
3344+
"tsconfig.json",
33083345
]
33093346
`;
33103347

src/templates/InstantSearch.js/index.html.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<div id="pagination"></div>
4949
</div>
5050

51-
<script src="https://cdn.jsdelivr.net/algoliasearch/3.32.0/algoliasearchLite.min.js"></script>
51+
<script src="https://cdn.jsdelivr.net/algoliasearch/4.10.4/algoliasearchLite.min.js"></script>
5252
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@{{libraryVersion}}"></script>
5353
<script src="./src/app.js"></script>
5454
</body>

src/templates/InstantSearch.js/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
"eslint-plugin-prettier": "3.1.2",
1919
"parcel-bundler": "1.12.5",
2020
"prettier": "1.19.1"
21+
},
22+
"dependencies": {
23+
"algoliasearch": "4.10.4",
24+
"instantsearch.js": "{{libraryVersion}}"
2125
}
2226
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import algoliasearch from 'algoliasearch/lite';
2+
import instantsearch from 'instantsearch.js/dist/instantsearch.production.min';
3+
4+
declare global {
5+
interface Window {
6+
algoliasearch: typeof algoliasearch;
7+
instantsearch: typeof instantsearch;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"esModuleInterop": true,
5+
"sourceMap": true,
6+
"allowJs": true,
7+
"lib": [
8+
"es6",
9+
"dom"
10+
],
11+
"rootDir": "src",
12+
"moduleResolution": "node"
13+
},
14+
"include": [
15+
"src",
16+
"src/global.d.ts"
17+
]
18+
}

0 commit comments

Comments
 (0)