Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp builds #800

Merged
merged 10 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 3 additions & 47 deletions .config/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,50 +39,6 @@ var resolve_config = nodeResolve({
});


// esm & cjs
const inputs = [
'tom-select.ts',
'tom-select.complete.ts',
'tom-select.popular.ts',
'utils.ts',
];
Comment on lines -42 to -48
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These builds are now handled by tsc.


inputs.forEach((slug)=>{

let input = path.resolve(__dirname,'../src',slug)

// esm
configs.push({
input: input,
output:{
//file: path.resolve(__dirname,'../build/esm',slug),
dir: path.resolve(__dirname,'../build/esm'),
format: 'esm',
preserveModules: false,
sourcemap: true,
banner: banner,
},
plugins:[babel_config,resolve_config,],
});

// cjs
configs.push({
input: input,
output:{
dir: path.resolve(__dirname,'../build/cjs'),
format: 'cjs',
preserveModules: false,
sourcemap: true,
banner: banner,
exports: "auto",
},
plugins:[babel_config,resolve_config],
});

});



var terser_config = terser({
mangle: true,
//toplevel: true, // removes tomSelect footer
Expand Down Expand Up @@ -128,7 +84,7 @@ function configCore( input, filename, plugins ){

var output = {
name: 'TomSelect',
file: `build/js/${filename}`,
file: `dist/js/${filename}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT the build/dist distinction wasn't useful. I opted to just directly construct everything in dist, which simplified things a bit.

footer: 'var tomSelect=function(el,opts){return new TomSelect(el,opts);} ',
};

Expand Down Expand Up @@ -156,15 +112,15 @@ var plugin_dir = path.resolve(__dirname,'../src/plugins');
var files = fs.readdirSync( plugin_dir );
files.map(function(file){
let input = path.resolve(__dirname,'../src/plugins',file,'plugin.ts');
let output = {file:`build/js/plugins/${file}.js`,'name':file};
let output = {file:`dist/js/plugins/${file}.js`,'name':file};
pluginConfig( input, output);


// esm
configs.push({
input: input,
output:{
file: path.resolve(__dirname,'../build/esm/plugins',file,'plugin.js'),
file: path.resolve(__dirname,'../dist/esm/plugins',file,'plugin.js'),
format: 'esm',
preserveModules: false,
sourcemap: true,
Expand Down
8 changes: 8 additions & 0 deletions .config/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "../dist/cjs"
}
}
7 changes: 7 additions & 0 deletions .config/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "NodeNext",
"outDir": "../dist/esm"
}
}
26 changes: 11 additions & 15 deletions .config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
"checkJs": true,
"strict": true,
"target": "ES6",
"module": "esnext",
"noUnusedLocals": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"alwaysStrict": true,
"strictNullChecks": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"allowUnreachableCode": false,
"noUncheckedIndexedAccess": true,

"lib": [
"ESNext",
"dom"
],

"strictNullChecks": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"allowUnreachableCode": false,
"noUncheckedIndexedAccess": true,
"declaration": true,
"declarationDir": "../dist/types",
"isolatedModules": true,
"moduleResolution": "node"
"sourceMap": true,
"rewriteRelativeImportExtensions": true,

"lib": ["ESNext", "dom"],
},
}
11 changes: 11 additions & 0 deletions .config/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// This exists for backwards compatibility. In the wild, folks are importing
// paths like `tom-select/dist/types/...`.
//
// Consider removing this in the next major version.
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/types",
"emitDeclarationOnly": true
}
}
10 changes: 9 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
indent_style = tab
tab_width = 4

[package.json]
indent_style = space
indent_size = 2

[.github/workflows/*]
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2
indent_size = 2
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Node.js CI

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: ['18.x', '20.x', '22.x']

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm run test
- run: npm run test:types
- run: npm run stylelint
32 changes: 0 additions & 32 deletions .github/workflows/stylelint.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/tests.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.DS_Store
.vscode
.DAV
node_modules
*.log
*.tmp.*
package-lock.json
*.lock
build/*
build-docs/*
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run test:typescript
npm run build:types
npm run stylelint
44 changes: 22 additions & 22 deletions Gruntfile.js → Gruntfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module.exports = function(grunt) {
var matched_files = grunt.file.expand(['src/plugins/*/plugin.scss']);
for (var i = 0, n = matched_files.length; i < n; i++) {
var plugin_name = matched_files[i].match(/src\/plugins\/(.+?)\//)[1];
scss_plugin_files.push({src: matched_files[i], dest: 'build/scss/plugins/' + plugin_name + '.scss'});
scss_plugin_files.push({src: matched_files[i], dest: 'dist/scss/plugins/' + plugin_name + '.scss'});
}


Expand Down Expand Up @@ -177,22 +177,22 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

// delete old build files
// delete old files
clean: {
library: ['build/scss/*','build/js/*','build/esm/*','build/css/*','build/cjs/*'],
library: ['dist/*'],
builddocs: ['build-docs/*']
},

// copy scss files to build folder
copy: {
scss:{
files: [{
'build/scss/tom-select.scss': ['src/scss/tom-select.scss'],
'build/scss/tom-select.default.scss': ['src/scss/tom-select.default.scss'],
'build/scss/tom-select.bootstrap4.scss': ['src/scss/tom-select.bootstrap4.scss'],
'build/scss/tom-select.bootstrap5.scss': ['src/scss/tom-select.bootstrap5.scss'],
'build/scss/_dropdown.scss': ['src/scss/_dropdown.scss'],
'build/scss/_items.scss': ['src/scss/_items.scss'],
'dist/scss/tom-select.scss': ['src/scss/tom-select.scss'],
'dist/scss/tom-select.default.scss': ['src/scss/tom-select.default.scss'],
'dist/scss/tom-select.bootstrap4.scss': ['src/scss/tom-select.bootstrap4.scss'],
'dist/scss/tom-select.bootstrap5.scss': ['src/scss/tom-select.bootstrap5.scss'],
'dist/scss/_dropdown.scss': ['src/scss/_dropdown.scss'],
'dist/scss/_items.scss': ['src/scss/_items.scss'],
}]
},
scss_plugins:{
Expand All @@ -206,8 +206,8 @@ module.exports = function(grunt) {
css_post: {
options: version_replace_options,
files: [
{expand: true, flatten: false, src: ['build/css/*.css'], dest: ''},
{expand: true, flatten: false, src: ['build/scss/*.scss'], dest: ''},
{expand: true, flatten: false, src: ['dist/css/*.css'], dest: ''},
{expand: true, flatten: false, src: ['dist/scss/*.scss'], dest: ''},
]
},
builddocs:{
Expand All @@ -219,7 +219,7 @@ module.exports = function(grunt) {
},
scss_plugin_paths: {
options: scss_plugin_path_replace_options,
files: [{expand: true, flatten: false, src: ['build/scss/tom-select.scss'], dest: ''}]
files: [{expand: true, flatten: false, src: ['dist/scss/tom-select.scss'], dest: ''}]
},
},

Expand All @@ -232,10 +232,10 @@ module.exports = function(grunt) {
},
build: {
files: [{
'build/css/tom-select.css': ['src/scss/tom-select.scss'],
'build/css/tom-select.default.css': ['src/scss/tom-select.default.scss'],
'build/css/tom-select.bootstrap4.css': ['src/scss/-tom-select.bootstrap4.scss'],
'build/css/tom-select.bootstrap5.css': ['src/scss/-tom-select.bootstrap5.scss'],
'dist/css/tom-select.css': ['src/scss/tom-select.scss'],
'dist/css/tom-select.default.css': ['src/scss/tom-select.default.scss'],
'dist/css/tom-select.bootstrap4.css': ['src/scss/-tom-select.bootstrap4.scss'],
'dist/css/tom-select.bootstrap5.css': ['src/scss/-tom-select.bootstrap5.scss'],
}]
},
builddocs: {
Expand All @@ -261,7 +261,7 @@ module.exports = function(grunt) {
autoprefixer,
]
},
files: [{expand: true, flatten: false, src: ['build/css/*.css'], dest: ''}],
files: [{expand: true, flatten: false, src: ['dist/css/*.css'], dest: ''}],
},
min: {
options: {
Expand All @@ -273,10 +273,10 @@ module.exports = function(grunt) {
]
},
files: [{
'build/css/tom-select.min.css': ['build/css/tom-select.css'],
'build/css/tom-select.default.min.css': ['build/css/tom-select.default.css'],
'build/css/tom-select.bootstrap4.min.css': ['build/css/tom-select.bootstrap4.css'],
'build/css/tom-select.bootstrap5.min.css': ['build/css/tom-select.bootstrap5.css'],
'dist/css/tom-select.min.css': ['dist/css/tom-select.css'],
'dist/css/tom-select.default.min.css': ['dist/css/tom-select.default.css'],
'dist/css/tom-select.bootstrap4.min.css': ['dist/css/tom-select.bootstrap4.css'],
'dist/css/tom-select.bootstrap5.min.css': ['dist/css/tom-select.bootstrap5.css'],
}]
},
builddocs:{
Expand Down Expand Up @@ -316,7 +316,7 @@ module.exports = function(grunt) {
command: 'npx rollup -c .config/rollup.docs.mjs',
},
buildjs: {
command: 'npx rollup -c .config/rollup.config.mjs',
command: 'npm run build:js',
},
},

Expand Down
12 changes: 6 additions & 6 deletions doc_src/pages/docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ If you don't need any plugins, or want to load plugins individually, use <code>t
Add plugins to your project by including their js files and calling `TomSelect.define`.

```js
import TomSelect from 'tom-select/dist/js/tom-select.base.js';
import TomSelect_remove_button from 'tom-select/dist/js/plugins/remove_button.js';
import TomSelect_dropdown_header from 'tom-select/dist/js/plugins/dropdown_header.js';
import TomSelect from 'tom-select/base';
import TomSelect_remove_button from 'tom-select/plugins/remove_button.js';
import TomSelect_dropdown_header from 'tom-select/dropdown_header.js';
Comment on lines +52 to +54
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is cleaner and transparently handles ESM vs. CJS. This is enabled by the new exports in package.json.


TomSelect.define('remove_button', TomSelect_remove_button);
TomSelect.define('dropdown_header', TomSelect_dropdown_header);
Expand All @@ -60,10 +60,10 @@ TomSelect.define('dropdown_header', TomSelect_dropdown_header);
Alternatively you can `require` plugins directly if your build tool supports it.

```js
import TomSelect from 'tom-select/dist/js/tom-select.base.js';
import TomSelect from 'tom-select/base';

TomSelect.define('remove_button', require('tom-select/dist/js/plugins/remove_button.js'));
TomSelect.define('dropdown_header', require('tom-select/dist/js/plugins/dropdown_header.js'));
TomSelect.define('remove_button', require('tom-select/plugins/remove_button.js'));
TomSelect.define('dropdown_header', require('tom-select/plugins/dropdown_header.js'));
```


Expand Down
Loading
Loading