Skip to content

Commit

Permalink
fix: avoid barrel files, keep only 1 entry file (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding authored Oct 5, 2024
1 parent 2c10ebd commit 64e895b
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 51 deletions.
3 changes: 3 additions & 0 deletions packages/multiple-select-vanilla/build-prod.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ for (const format of buildFormats) {
outfile: `dist/locales/multiple-select-all-locales.${extension}`,
});

// - let's use TSUP to get valid hybrid (CJS/ESM) approach with are-the-types-wrong, however keep the rest of the build
// finally, create a regular bundle as a standalone which will be accessible as MultipleSelect from the global window object
// this file is basically a legacy alternative to import via a <script> tag
/*
runBuild({
format,
globalName: 'MultipleSelect',
outfile: `dist/browser/multiple-select.${extension}`,
});
*/
}

function runBuild(options) {
Expand Down
10 changes: 6 additions & 4 deletions packages/multiple-select-vanilla/src/MultipleSelectInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* @author zhixin wen <[email protected]>
*/
import Constants from './constants';
import type { HtmlStruct, MultipleSelectLocales, OptGroupRowData, OptionDataObject, OptionRowData } from './interfaces';
import type { CloseReason, MultipleSelectOption } from './interfaces/multipleSelectOption.interface';
import { BindingEventService, VirtualScroll } from './services';
import { compareObjects, deepCopy, findByParam, removeDiacritics, removeUndefined, setDataKeys, stripScripts } from './utils';
import type { HtmlStruct, OptGroupRowData, OptionDataObject, OptionRowData } from './models/interfaces';
import type { MultipleSelectLocales } from './models/locale.interface';
import type { CloseReason, MultipleSelectOption } from './models/multipleSelectOption.interface';
import { BindingEventService } from './services/binding-event.service';
import { VirtualScroll } from './services/virtual-scroll';
import { compareObjects, deepCopy, findByParam, removeDiacritics, removeUndefined, setDataKeys, stripScripts } from './utils/utils';
import {
calculateAvailableSpace,
classNameToList,
Expand Down
3 changes: 2 additions & 1 deletion packages/multiple-select-vanilla/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { LabelFilter, MultipleSelectOption, TextFilter } from './interfaces';
import type { LabelFilter, TextFilter } from './models/interfaces';
import type { MultipleSelectOption } from './models/multipleSelectOption.interface';
import English from './locales/multiple-select-en-US';

const BLOCK_ROWS = 50;
Expand Down
42 changes: 36 additions & 6 deletions packages/multiple-select-vanilla/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
export * from './services';
export * from './constants';
export * from './interfaces';
export * from './utils';
export * from './multiple-select';
export * from './MultipleSelectInstance';
export type * from './models/interfaces';
export type * from './models/locale.interface';
export type * from './models/multipleSelectOption.interface';
export { BindingEventService, type ElementEventListener } from './services/binding-event.service';
export { VirtualScroll } from './services/virtual-scroll';
export {
type HtmlElementPosition,
calculateAvailableSpace,
classNameToList,
convertItemRowToHtml,
createDomElement,
createDomStructure,
emptyElement,
findParent,
getElementOffset,
getElementSize,
insertAfter,
omitProp,
toggleElement,
toggleElementClass,
windowScrollPosition,
} from './utils/domUtils';
export {
compareObjects,
deepCopy,
findByParam,
isDefined,
objectRemoveEmptyProps,
removeDiacritics,
removeUndefined,
setDataKeys,
stripScripts,
toCamelCase,
} from './utils/utils';
export { multipleSelect } from './multiple-select';
export { MultipleSelectInstance } from './MultipleSelectInstance';
3 changes: 0 additions & 3 deletions packages/multiple-select-vanilla/src/interfaces/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { MultipleSelectInstance } from '../MultipleSelectInstance';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces';
import type { MultipleSelectLocale, MultipleSelectLocales } from '../models/locale.interface';

const ms =
typeof window !== 'undefined' && window.multipleSelect !== undefined
Expand Down
4 changes: 2 additions & 2 deletions packages/multiple-select-vanilla/src/multiple-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import { MultipleSelectInstance } from './MultipleSelectInstance';
import Constants from './constants';
import type { MultipleSelectLocales } from './interfaces';
import type { MultipleSelectOption } from './interfaces/multipleSelectOption.interface';
import type { MultipleSelectLocales } from './models/locale.interface';
import type { MultipleSelectOption } from './models/multipleSelectOption.interface';
import English from './locales/multiple-select-en-US';

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/multiple-select-vanilla/src/services/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Constants from '../constants';
import type { HtmlStruct, VirtualCache, VirtualScrollOption } from '../interfaces';
import { convertItemRowToHtml, emptyElement } from '../utils';
import type { HtmlStruct, VirtualCache, VirtualScrollOption } from '../models/interfaces';
import { convertItemRowToHtml, emptyElement } from '../utils/domUtils';

export class VirtualScroll {
protected clusterRows?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/multiple-select-vanilla/src/utils/domUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HtmlStruct, InferDOMType } from '../interfaces';
import type { HtmlStruct, InferDOMType } from '../models/interfaces';
import { objectRemoveEmptyProps } from './utils';

export interface HtmlElementPosition {
Expand Down
2 changes: 0 additions & 2 deletions packages/multiple-select-vanilla/src/utils/index.ts

This file was deleted.

28 changes: 14 additions & 14 deletions packages/multiple-select-vanilla/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'tsup';
export default defineConfig(options => [
// for bundlers like vite, rollup, esbuild, webpack etc
{
entry: ['src/**.ts'],
entry: ['src/index.ts'],
format: ['esm'],
splitting: false,
sourcemap: true,
Expand All @@ -27,17 +27,17 @@ export default defineConfig(options => [
},

// IIFE bundle js for cdn (window object for legacy <script>)
// {
// entry: {
// 'multiple-select': 'src/index.ts',
// },
// format: ['iife'],
// globalName: 'MultipleSelect',
// splitting: false,
// sourcemap: true,
// clean: true,
// outExtension: ({ format }) => ({
// js: '.iife.js',
// }),
// },
{
entry: {
'browser/multiple-select': 'src/index.ts',
},
format: ['iife'],
globalName: 'MultipleSelect',
splitting: false,
sourcemap: true,
// clean: true,
outExtension: ({ format }) => ({
js: '.iife.js',
}),
},
]);

0 comments on commit 64e895b

Please sign in to comment.