Skip to content

Commit

Permalink
chore!: convert addon to v2 format
Browse files Browse the repository at this point in the history
This is breaking change as it now requires the consuming addon or the add to have ember-auto-import >= v2
  • Loading branch information
SergeAstapov committed May 26, 2022
1 parent 6f0248b commit f6c9ded
Show file tree
Hide file tree
Showing 18 changed files with 506 additions and 44 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ The `cookies` service has methods for reading and writing cookies:
* `exists(name)`: checks whether a cookie exists at all (even with a falsy
value) and returns `true` if that is the case or `false` otherwise.

## Testing

`ember-cookies` exposes `clearAllCookies` test helper that allows to start a test without any cookies:

```js
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { clearAllCookies } from 'ember-cookies/test-support';

module('Unit | Some Module', function (hooks) {
setupTest(hooks);

hooks.beforeEach(function () {
clearAllCookies();
});

// or you may wat to clear cookies after the test run
hooks.afterEach(function () {
clearAllCookies();
});
});
```

## License

`ember-cookies` is developed by and ©
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
"lint:test-app": "yarn workspace test-app run lint",
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:fix:*",
"lint:fix:addon": "yarn workspace ember-cookies run lint:fix",
"lint:fix:test-app": "yarn workspace test-app run lint:fix"
"lint:fix:test-app": "yarn workspace test-app run lint:fix",
"prepare": "yarn workspace ember-cookies run build",
"start": "npm-run-all --parallel start:*",
"start:addon": "yarn workspace ember-cookies run start",
"start:test-app": "yarn workspace test-app run start",
"test": "npm-run-all --aggregate-output --continue-on-error --parallel \"test:!(watch)\"",
"test:watch": "npm-run-all --aggregate-output --continue-on-error --parallel test:watch:*",
"test:test-app": "yarn workspace test-app run test",
"test:watch:test-app": "yarn workspace test-app run test:watch",
"test:watch:addon": "yarn workspace ember-cookies run start"
},
"devDependencies": {
"npm-run-all": "^4.1.5"
Expand Down
9 changes: 0 additions & 9 deletions packages/ember-cookies/.babelrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/ember-cookies/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ module.exports = {
'.eslintrc.js',
'**/.eslintrc.js',
'.prettierrc.js',
'index.js',
'addon-main.js',
'blueprints/*/index.js',
'config/**/*.js',
],
excludedFiles: ['addon/**', 'addon-test-support/**'],
excludedFiles: ['src/**'],
parserOptions: {
sourceType: 'script',
},
Expand Down
8 changes: 3 additions & 5 deletions packages/ember-cookies/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

# compiled output
/dist
/tmp

# dependencies
/node_modules
/bower_components

# misc
/.eslintcache
Expand All @@ -19,6 +17,6 @@ yarn-error.log
testem.log
.DS_Store

# ember-try
.node_modules.ember-try/
package.json.ember-try
# .md copies from release
/CHANGELOG.md
/README.md
2 changes: 2 additions & 0 deletions packages/ember-cookies/addon-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { addonV1Shim } = require('@embroider/addon-shim');
module.exports = addonV1Shim(__dirname);
Empty file.
Empty file.
3 changes: 0 additions & 3 deletions packages/ember-cookies/app/services/cookies.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/ember-cookies/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
]
}
12 changes: 0 additions & 12 deletions packages/ember-cookies/index.js

This file was deleted.

35 changes: 31 additions & 4 deletions packages/ember-cookies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,51 @@
"keywords": [
"ember-addon"
],
"repository": "https://github.com/simplabs/ember-cookies",
"license": "MIT",
"author": "",
"exports": {
".": "./dist/index.js",
"./*": "./dist/*",
"./test-support": "./dist/test-support/index.js",
"./addon-main.js": "./addon-main.js"
},
"directories": {
"doc": "doc",
"test": "tests"
},
"repository": "https://github.com/simplabs/ember-cookies",
"files": [
"addon-main.js",
"dist"
],
"scripts": {
"build": "rollup --config",
"copyDoc": "cp ../../*.md .",
"lint": "yarn lint:js",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix"
"lint:js:fix": "eslint . --fix",
"prepublishOnly": "npm-run-all --aggregate-output --continue-on-error --parallel copyDoc build",
"start": "rollup --config --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
},
"dependencies": {
"ember-cli-babel": "^7.26.3",
"@embroider/addon-shim": "^1.7.1",
"ember-native-class-polyfill": "^1.0.6"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/eslint-parser": "^7.17.0",
"@babel/plugin-proposal-class-properties": "^7.17.12",
"@babel/plugin-proposal-decorators": "^7.18.2",
"@embroider/addon-dev": "^1.7.1",
"@rollup/plugin-babel": "^5.3.1",
"eslint": "^8.0.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-ember": "^10.3.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "2.6.2"
"prettier": "2.6.2",
"rollup": "^2.74.1"
},
"engines": {
"node": ">= 12.*"
Expand All @@ -37,8 +58,14 @@
"edition": "octane"
},
"ember-addon": {
"main": "addon-main.js",
"type": "addon",
"version": 2,
"versionCompatibility": {
"ember": ">=3.4"
},
"app-js": {
"./services/cookies.js": "./dist/_app_/services/cookies.js"
}
}
}
54 changes: 54 additions & 0 deletions packages/ember-cookies/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import babel from '@rollup/plugin-babel';
import { Addon } from '@embroider/addon-dev/rollup';

const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
output: addon.output(),

plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints([
'services/**/*.js',
'test-support/**/*.js',
'utils/**/*.js',
'clear-all-cookies.js',
]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports(['services/cookies.js']),

// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
//
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: 'bundled',
}),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),

// Remove leftover build artifacts when starting a new build.
addon.clean(),
],
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { assert } from '@ember/debug';
import { assign as emberAssign } from '@ember/polyfills';
import { isEmpty } from '@ember/utils';
import { serializeCookie } from 'ember-cookies/utils/serialize-cookie';
import { serializeCookie } from './utils/serialize-cookie';

const assign = Object.assign || emberAssign;

export default function (options = {}) {
export default function clearAllCookies(options = {}) {
assert('Cookies cannot be set to be HTTP-only from a browser!', !options.httpOnly);
assert(
'Expires, Max-Age, and raw options cannot be set when clearing cookies',
Expand Down
1 change: 1 addition & 0 deletions packages/ember-cookies/src/test-support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as clearAllCookies } from '../clear-all-cookies';
Loading

0 comments on commit f6c9ded

Please sign in to comment.