Skip to content

Commit

Permalink
Merge pull request #773 from embroider-build/addon-shim
Browse files Browse the repository at this point in the history
Updates to addon shim
  • Loading branch information
ef4 authored Apr 24, 2021
2 parents acec073 + 503b0b8 commit 6e427f6
Show file tree
Hide file tree
Showing 20 changed files with 406 additions and 92 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
/packages/macros/**/*.d.ts
/packages/util/src/**/*.js
/packages/util/src/**/*.d.ts
/packages/util/shim.js
/packages/util/shim.d.ts
/packages/webpack/**/*.js
/packages/webpack/**/*.d.ts
/packages/hbs-loader/**/*.js
Expand Down
23 changes: 23 additions & 0 deletions packages/addon-shim/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/
/src/**/*.js
/src/**/*.d.ts

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
81 changes: 81 additions & 0 deletions packages/addon-shim/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.prettierrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'addon-main.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js',
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**',
],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
// node typescript files
{
files: ['src/**/*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
extends: ['prettier/@typescript-eslint'],
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'typeLike',
format: ['PascalCase'],
},
],
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' },
],
'no-unused-vars': 'off',
'@typescript-eslint/no-require-imports': 'error',
},
},
],
};
29 changes: 29 additions & 0 deletions packages/addon-shim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/
/src/**/*.js
/src/**/*.d.ts
/src/**/*.map

# dependencies
/bower_components/
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
33 changes: 33 additions & 0 deletions packages/addon-shim/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# compiled output
/dist/
/tmp/

# dependencies
/bower_components/

# misc
/.bowerrc
/.editorconfig
/.ember-cli
/.env*
/.eslintcache
/.eslintignore
/.eslintrc.js
/.git/
/.gitignore
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
/bower.json
/config/ember-try.js
/CONTRIBUTING.md
/ember-cli-build.js
/testem.js
/tests/
/yarn.lock
.gitkeep

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
21 changes: 21 additions & 0 deletions packages/addon-shim/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
5 changes: 5 additions & 0 deletions packages/addon-shim/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
singleQuote: true,
};
3 changes: 3 additions & 0 deletions packages/addon-shim/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
}
64 changes: 64 additions & 0 deletions packages/addon-shim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# @embroider/addon-shim

Makes a v2 addon work like a v1 addon so it can be used in a classic (non-Embroider) app.

This allows addons to update to v2 without waiting for all their users to upgrade to Embroider.

## Compatibility

- Ember.js v3.13 or above
- Ember CLI v2.13 or above
- Node.js v10 or above

## Installation

```
ember install @embroider/util
```

## Usage

To use it:

1. Be prepared to do a semver major release of your addon, because the shim demands that the app has ember-auto-import >= 2.
2. Create an `addon-main.js` file that requires and invokes the shim:

```js
const { addonV1Shim } = require('@embroider/addon-shim');
module.exports = addonV1Shim(__dirname);
```

3. Update your `package.json` to point at addon-main.js:

```json
{
"ember-addon": {
"version": 2,
"type": "addon",
"main": "addon-main.js"
}
}
```

### Shim Options

**disabled**: this optional argument lets you control whether your shimmed addon will emit `'app-js'` and `'public-assets'` into non-embroider builds. Example:

```js
module.exports = addonV1Shim(__dirname, {
disabled(options) {
let welcomeConfig = options['ember-welcome-page'] || {};
return process.env.EMBER_ENV === 'production' && !welcomeConfig.enabled;
},
});
```

This option _only_ works in non-embroider builds. Under embroider, apps just won't import the parts of your addon they don't want.

## Contributing

See the top-level CONTRIBUTING.md in this monorepo.

## License

This project is licensed under the MIT License.
12 changes: 12 additions & 0 deletions packages/addon-shim/addon-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

module.exports = {
name: require('./package').name,

included(...args) {
this._super.included.apply(this, args);
this.addons
.find((a) => a.name === 'ember-auto-import')
.registerV2Addon(this.parent.name, this.parent.pkg.root);
},
};
48 changes: 48 additions & 0 deletions packages/addon-shim/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@embroider/addon-shim",
"version": "0.39.1",
"description": "Make v2 addons work in non-Embroider apps.",
"keywords": [
"ember-addon"
],
"main": "./src/index.js",
"repository": "",
"license": "MIT",
"author": "",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"prepare": "tsc",
"build": "ember build --environment=production",
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel 'lint:!(fix)'",
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
"lint:hbs": "ember-template-lint .",
"lint:hbs:fix": "ember-template-lint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"test": "npm-run-all lint test:*",
"test:ember": "cross-env EMBROIDER_TEST_SETUP_FORCE=embroider EMBROIDER_TEST_SETUP_OPTIONS=optimized ember test --test-port=0",
"test:classic": "cross-env EMBROIDER_TEST_SETUP_FORCE=classic ember test --test-port=0",
"test:ember-compatibility": "ember try:each"
},
"dependencies": {
"@embroider/shared-internals": "^0.39.1",
"ember-auto-import": "2.0.0-alpha.0",
"semver": "^7.3.4"
},
"devDependencies": {
"@types/semver": "^7.3.4"
},
"engines": {
"node": "10.* || >= 12"
},
"ember-addon": {
"main": "addon-main.js"
},
"volta": {
"extends": "../../package.json"
}
}
Loading

0 comments on commit 6e427f6

Please sign in to comment.