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

chore!: convert addon to v2 format #747

Merged
merged 1 commit into from
May 30, 2022
Merged
Changes from all 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
chore!: convert addon to v2 format
This is breaking change as it now requires the consuming addon or the add to have ember-auto-import >= v2
  • Loading branch information
SergeAstapov authored and marcoow committed May 30, 2022
commit 7b108c428247e6fbfbf239103dc45ff386604379
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -60,6 +60,30 @@ 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 the `clearAllCookies` test helper that clears
all known cookies to reset state before and/or after tests:

```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 ©
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is needed to build the addon as v2 addon needs to be prebuilt before consumption

"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"
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
@@ -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',
},
8 changes: 3 additions & 5 deletions packages/ember-cookies/.gitignore
Original file line number Diff line number Diff line change
@@ -2,11 +2,9 @@

# compiled output
/dist
/tmp

# dependencies
/node_modules
/bower_components

# misc
/.eslintcache
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to make those files explorable on github, we keep them in the root folder.

to make those files packed at publish time, we copy them to the addon folder.
This allows to keep single source of truth and at the same time keep all the nice parts of DX

/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
@@ -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 .",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is where copy of the files happens.

"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": ">= 14.*"
@@ -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',
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';
2 changes: 1 addition & 1 deletion packages/test-app/tests/unit/clear-all-cookies-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import clearAllCookies from 'ember-cookies/clear-all-cookies';
import { clearAllCookies } from 'ember-cookies/test-support';

function randomString() {
return Math.random().toString(36).substring(2);
Loading