Skip to content

Commit

Permalink
add option to disable initializer's auto-import of flatpickr
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryD committed Feb 13, 2024
1 parent 2fed10b commit 3f08ac0
Show file tree
Hide file tree
Showing 6 changed files with 652 additions and 297 deletions.
11 changes: 10 additions & 1 deletion ember-flatpickr/addon-main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

const { addonV1Shim } = require("@embroider/addon-shim");

module.exports = addonV1Shim(__dirname);
module.exports = {
...addonV1Shim(__dirname),
options: {
"@embroider/macros": {
setOwnConfig: {
initializeFlatpickr: true,
},
},
}
};
7 changes: 4 additions & 3 deletions ember-flatpickr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,25 @@
},
"dependencies": {
"@ember/render-modifiers": "^2.0.3",
"@ember/test-helpers": "~3.2.1",
"@embroider/addon-shim": "^1.8.7",
"@ember/test-helpers": "~3.2.1"
"@embroider/macros": "^1.13.5"
},
"devDependencies": {
"@babel/core": "^7.23.9",
"@glimmer/component": "~1.1.2",
"ember-template-lint": "~5.13.0",
"@babel/plugin-proposal-decorators": "^7.23.9",
"@babel/plugin-transform-class-properties": "^7.22.5",
"@babel/plugin-transform-class-static-block": "^7.23.4",
"@babel/plugin-transform-typescript": "^7.23.6",
"@babel/runtime": "^7.23.9",
"@embroider/addon-dev": "^4.2.1",
"@glimmer/component": "~1.1.2",
"@rollup/plugin-babel": "^6.0.4",
"@tsconfig/ember": "^3.0.3",
"babel-plugin-ember-template-compilation": "^2.2.1",
"concurrently": "^8.0.1",
"ember-source": "~5.6.0",
"ember-template-lint": "~5.13.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-ember": "^11.12.0",
Expand Down
18 changes: 14 additions & 4 deletions ember-flatpickr/src/initializers/ember-flatpickr.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import flatpickr from 'flatpickr';
import { importSync, macroCondition, getOwnConfig } from '@embroider/macros';

/*
* This file is only here to initialize the flatpickr registry at the start of the app
* This behavior can be disabled by setting `initializeFlatpickr` to `false` in the `@embroider/macros` config. The module will be then tree-shaken away if not used in the app.
*/
interface FlatpickrConfig {
initializeFlatpickr: boolean;
}

if (macroCondition(getOwnConfig<FlatpickrConfig>()?.initializeFlatpickr)) {
importSync('flatpickr');
}

export function initialize() {
if (window) {
window.flatpickr = flatpickr;
}
// noop
}

export default {
Expand Down
Loading

0 comments on commit 3f08ac0

Please sign in to comment.