Skip to content

Commit 2bd1eff

Browse files
committed
Fixing TypeScript build system
We no longer parse ALL .ts files for EACH package we're building with rollup. Also, we ouput the the type files straight from rollup
1 parent 4918994 commit 2bd1eff

File tree

4 files changed

+57
-30
lines changed

4 files changed

+57
-30
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ jobs:
3333
- run: yarn check-format
3434

3535
js-dist-current:
36-
# always skip check for now - building is too inefficient and large for CI
37-
if: false
3836
runs-on: ubuntu-latest
3937
steps:
4038
- uses: actions/checkout@master

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"private": true,
3-
"workspaces": [
4-
"src/*/assets"
5-
],
3+
"workspaces": ["src/*/assets"],
64
"scripts": {
75
"build": "yarn rollup -c",
8-
"build:types": "tsc --declaration --emitDeclarationOnly || node bin/move_types.js",
96
"test": "yarn workspaces run jest",
107
"lint": "yarn workspaces run eslint src test",
118
"format": "prettier src/*/assets/src/*.ts src/*/assets/test/*.js {,src/*/}*.{json,md} --write",

rollup.config.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ const wildcardExternalsPlugin = (peerDependencies) => ({
3838
}
3939
});
4040

41+
/**
42+
* Moves the generated TypeScript declaration files to the correct location.
43+
*
44+
* This could probably be configured in the TypeScript plugin.
45+
*/
46+
const moveTypescriptDeclarationsPlugin = (packagePath) => ({
47+
name: 'move-ts-declarations',
48+
writeBundle: async () => {
49+
const files = glob.sync(path.join(packagePath, 'dist', '*', 'assets', 'src', '**/*.d.ts'));
50+
files.forEach((file) => {
51+
// a bit odd, but remove first 7 directories, which will leave
52+
// only the relative path to the file
53+
const relativePath = file.split('/').slice(7).join('/');
54+
55+
const targetFile = path.join(packagePath, 'dist', relativePath);
56+
if (!fs.existsSync(path.dirname(targetFile))) {
57+
fs.mkdirSync(path.dirname(targetFile), { recursive: true });
58+
}
59+
fs.renameSync(file, targetFile);
60+
});
61+
}
62+
});
63+
4164
const files = glob.sync('src/*/assets/src/*controller.ts');
4265
module.exports = files.map((file) => {
4366
const packageRoot = path.join(file, '..', '..');
@@ -57,13 +80,22 @@ module.exports = files.map((file) => {
5780
external: peerDependencies,
5881
plugins: [
5982
resolve(),
60-
typescript(),
83+
typescript({
84+
filterRoot: packageRoot,
85+
include: ['src/**/*.ts'],
86+
compilerOptions: {
87+
outDir: 'dist',
88+
declaration: true,
89+
emitDeclarationOnly: true,
90+
}
91+
}),
6192
commonjs({
6293
namedExports: {
6394
'react-dom/client': ['createRoot'],
6495
},
6596
}),
6697
wildcardExternalsPlugin(peerDependencies),
98+
moveTypescriptDeclarationsPlugin(packageRoot),
6799
],
68100
};
69101
});

src/Autocomplete/assets/dist/controller.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
2222
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
2323
}
2424

25-
var _instances, _getCommonConfig, _createAutocomplete, _createAutocompleteWithHtmlContents, _createAutocompleteWithRemoteData, _stripTags, _mergeObjects, _createTomSelect, _dispatchEvent;
25+
var _default_1_instances, _default_1_getCommonConfig, _default_1_createAutocomplete, _default_1_createAutocompleteWithHtmlContents, _default_1_createAutocompleteWithRemoteData, _default_1_stripTags, _default_1_mergeObjects, _default_1_createTomSelect, _default_1_dispatchEvent;
2626
class default_1 extends Controller {
2727
constructor() {
2828
super(...arguments);
29-
_instances.add(this);
29+
_default_1_instances.add(this);
3030
}
3131
initialize() {
3232
this.element.setAttribute('data-live-ignore', '');
@@ -39,14 +39,14 @@ class default_1 extends Controller {
3939
}
4040
connect() {
4141
if (this.urlValue) {
42-
this.tomSelect = __classPrivateFieldGet(this, _instances, "m", _createAutocompleteWithRemoteData).call(this, this.urlValue, this.minCharactersValue);
42+
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocompleteWithRemoteData).call(this, this.urlValue, this.minCharactersValue);
4343
return;
4444
}
4545
if (this.optionsAsHtmlValue) {
46-
this.tomSelect = __classPrivateFieldGet(this, _instances, "m", _createAutocompleteWithHtmlContents).call(this);
46+
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocompleteWithHtmlContents).call(this);
4747
return;
4848
}
49-
this.tomSelect = __classPrivateFieldGet(this, _instances, "m", _createAutocomplete).call(this);
49+
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocomplete).call(this);
5050
}
5151
disconnect() {
5252
this.tomSelect.revertSettings.innerHTML = this.element.innerHTML;
@@ -77,7 +77,7 @@ class default_1 extends Controller {
7777
return this.preloadValue;
7878
}
7979
}
80-
_instances = new WeakSet(), _getCommonConfig = function _getCommonConfig() {
80+
_default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _default_1_getCommonConfig() {
8181
const plugins = {};
8282
const isMultiple = !this.selectElement || this.selectElement.multiple;
8383
if (!this.formElement.disabled && !isMultiple) {
@@ -109,19 +109,19 @@ _instances = new WeakSet(), _getCommonConfig = function _getCommonConfig() {
109109
if (!this.selectElement && !this.urlValue) {
110110
config.shouldLoad = () => false;
111111
}
112-
return __classPrivateFieldGet(this, _instances, "m", _mergeObjects).call(this, config, this.tomSelectOptionsValue);
113-
}, _createAutocomplete = function _createAutocomplete() {
114-
const config = __classPrivateFieldGet(this, _instances, "m", _mergeObjects).call(this, __classPrivateFieldGet(this, _instances, "m", _getCommonConfig).call(this), {
112+
return __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_mergeObjects).call(this, config, this.tomSelectOptionsValue);
113+
}, _default_1_createAutocomplete = function _default_1_createAutocomplete() {
114+
const config = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_mergeObjects).call(this, __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_getCommonConfig).call(this), {
115115
maxOptions: this.selectElement ? this.selectElement.options.length : 50,
116116
});
117-
return __classPrivateFieldGet(this, _instances, "m", _createTomSelect).call(this, config);
118-
}, _createAutocompleteWithHtmlContents = function _createAutocompleteWithHtmlContents() {
119-
const config = __classPrivateFieldGet(this, _instances, "m", _mergeObjects).call(this, __classPrivateFieldGet(this, _instances, "m", _getCommonConfig).call(this), {
117+
return __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createTomSelect).call(this, config);
118+
}, _default_1_createAutocompleteWithHtmlContents = function _default_1_createAutocompleteWithHtmlContents() {
119+
const config = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_mergeObjects).call(this, __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_getCommonConfig).call(this), {
120120
maxOptions: this.selectElement ? this.selectElement.options.length : 50,
121121
score: (search) => {
122122
const scoringFunction = this.tomSelect.getScoreFunction(search);
123123
return (item) => {
124-
return scoringFunction(Object.assign(Object.assign({}, item), { text: __classPrivateFieldGet(this, _instances, "m", _stripTags).call(this, item.text) }));
124+
return scoringFunction(Object.assign(Object.assign({}, item), { text: __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_stripTags).call(this, item.text) }));
125125
};
126126
},
127127
render: {
@@ -133,9 +133,9 @@ _instances = new WeakSet(), _getCommonConfig = function _getCommonConfig() {
133133
},
134134
},
135135
});
136-
return __classPrivateFieldGet(this, _instances, "m", _createTomSelect).call(this, config);
137-
}, _createAutocompleteWithRemoteData = function _createAutocompleteWithRemoteData(autocompleteEndpointUrl, minCharacterLength) {
138-
const config = __classPrivateFieldGet(this, _instances, "m", _mergeObjects).call(this, __classPrivateFieldGet(this, _instances, "m", _getCommonConfig).call(this), {
136+
return __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createTomSelect).call(this, config);
137+
}, _default_1_createAutocompleteWithRemoteData = function _default_1_createAutocompleteWithRemoteData(autocompleteEndpointUrl, minCharacterLength) {
138+
const config = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_mergeObjects).call(this, __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_getCommonConfig).call(this), {
139139
firstUrl: (query) => {
140140
const separator = autocompleteEndpointUrl.includes('?') ? '&' : '?';
141141
return `${autocompleteEndpointUrl}${separator}query=${encodeURIComponent(query)}`;
@@ -175,17 +175,17 @@ _instances = new WeakSet(), _getCommonConfig = function _getCommonConfig() {
175175
},
176176
preload: this.preload,
177177
});
178-
return __classPrivateFieldGet(this, _instances, "m", _createTomSelect).call(this, config);
179-
}, _stripTags = function _stripTags(string) {
178+
return __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createTomSelect).call(this, config);
179+
}, _default_1_stripTags = function _default_1_stripTags(string) {
180180
return string.replace(/(<([^>]+)>)/gi, '');
181-
}, _mergeObjects = function _mergeObjects(object1, object2) {
181+
}, _default_1_mergeObjects = function _default_1_mergeObjects(object1, object2) {
182182
return Object.assign(Object.assign({}, object1), object2);
183-
}, _createTomSelect = function _createTomSelect(options) {
184-
__classPrivateFieldGet(this, _instances, "m", _dispatchEvent).call(this, 'autocomplete:pre-connect', { options });
183+
}, _default_1_createTomSelect = function _default_1_createTomSelect(options) {
184+
__classPrivateFieldGet(this, _default_1_instances, "m", _default_1_dispatchEvent).call(this, 'autocomplete:pre-connect', { options });
185185
const tomSelect = new TomSelect(this.formElement, options);
186-
__classPrivateFieldGet(this, _instances, "m", _dispatchEvent).call(this, 'autocomplete:connect', { tomSelect, options });
186+
__classPrivateFieldGet(this, _default_1_instances, "m", _default_1_dispatchEvent).call(this, 'autocomplete:connect', { tomSelect, options });
187187
return tomSelect;
188-
}, _dispatchEvent = function _dispatchEvent(name, payload) {
188+
}, _default_1_dispatchEvent = function _default_1_dispatchEvent(name, payload) {
189189
this.element.dispatchEvent(new CustomEvent(name, { detail: payload, bubbles: true }));
190190
};
191191
default_1.values = {

0 commit comments

Comments
 (0)