-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add tests and automated publishing the package to NPM #96
Conversation
🦋 Changeset detectedLatest commit: fd32330 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this, these tests will help a lot. I've left a few comments and questions
Do I need to add an NPM_TOKEN environment variable to this repo before merging it?
.changeset/config.json
Outdated
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
{ "repo": "single-spa/single-spa-react" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ "repo": "single-spa/single-spa-react" } | |
{ "repo": "single-spa/import-map-overrides } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about this. Fixed.
.changeset/plenty-nails-lie.md
Outdated
"import-map-overrides": patch | ||
--- | ||
|
||
Add automation to publish package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems redundant to automate release flow
in the fast-chairs-guess.md
changeset. Let's remove this changeset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. This PR has been reworked so many times that with iterations (it has been reopened quite a few times) some comments went lost and some inconsistencies crept in. Removing this file.
rollup.config.js
Outdated
@@ -70,6 +70,7 @@ export default [ | |||
}, | |||
plugins: [ | |||
babel({ | |||
babelHelpers: "bundled", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Are we using generator syntax or something else that requires babel runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, when building we get the following warning:
src/import-map-overrides-server.js → dist/import-map-overrides-server.js...
babelHelpers: 'bundled' option was used by default. It is recommended to configure this option explicitly, read more here: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers
return promise.then(() => | ||
includes(imo.invalidExternalMaps, importMapUrl) | ||
return promise.then( | ||
() => !includes(imo.invalidExternalMaps, importMapUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bug that you fixed? Please link issue if there was one for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a bug I fixed. I discovered it when writing the tests.
The function is called isExternalMapValid
and should return true when the map IS valid, which means it is NOT included in the imo.invalidExternalMaps
array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no issue about this. The power of unit tests 🙂
src/api/js-api.js
Outdated
@@ -367,6 +373,7 @@ function init() { | |||
|
|||
function fireEvent(type) { | |||
// Set timeout so that event fires after the change has totally finished | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/api/localStorageMock.js
Outdated
@@ -0,0 +1,25 @@ | |||
// Mocks for the localStorage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems redundant to have local-storage-mock.js
and localStorageMock.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another left over from the many reopenings of this PR. Sorry about this. Removed.
src/server/server-api.js
Outdated
@@ -1,4 +1,4 @@ | |||
import cookie from "cookie"; | |||
const cookie = require("cookie"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change to CJS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use the ES syntax with the new version of cookie library we get the following error when building with rollup:
src/import-map-overrides-server.js → dist/import-map-overrides-server.js...
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
cookie (imported by src/server/server-api.js)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am hesitant about this change because it could impact a lot of things (bundling, tests, linter, etc). All ESM is better.
I read through the rollup documentation linked to in the warning you shared (https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) and the solution seems to be to add @rollup/plugin-node-resolve
rather than to change it to a CJS import. Is there an error even when rollup node resolve is present?
Have you tested that import-map-overrides works server-side after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed the comments.
.changeset/config.json
Outdated
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
{ "repo": "single-spa/single-spa-react" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about this. Fixed.
.changeset/plenty-nails-lie.md
Outdated
"import-map-overrides": patch | ||
--- | ||
|
||
Add automation to publish package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. This PR has been reworked so many times that with iterations (it has been reopened quite a few times) some comments went lost and some inconsistencies crept in. Removing this file.
rollup.config.js
Outdated
@@ -70,6 +70,7 @@ export default [ | |||
}, | |||
plugins: [ | |||
babel({ | |||
babelHelpers: "bundled", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, when building we get the following warning:
src/import-map-overrides-server.js → dist/import-map-overrides-server.js...
babelHelpers: 'bundled' option was used by default. It is recommended to configure this option explicitly, read more here: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers
src/api/js-api.js
Outdated
let parsedContent; | ||
try { | ||
parsedContent = JSON.parse(scriptEl.textContent); | ||
} catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced this when I wrote a test and I realized that, if we have an empty import map of the form:
<script type="importmap"></script>
this will make the parsing fail. I considered this would be an unwanted behaviour, hence the change. I understand your comment and I have now reverted this change and opened an issue to further discuss this and maybe reintroduce this in a separate PR.
#98
src/api/js-api.js
Outdated
let parsedContent; | ||
try { | ||
parsedContent = JSON.parse(scriptEl.textContent); | ||
} catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also modified the tests accordingly.
return promise.then(() => | ||
includes(imo.invalidExternalMaps, importMapUrl) | ||
return promise.then( | ||
() => !includes(imo.invalidExternalMaps, importMapUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a bug I fixed. I discovered it when writing the tests.
The function is called isExternalMapValid
and should return true when the map IS valid, which means it is NOT included in the imo.invalidExternalMaps
array.
return promise.then(() => | ||
includes(imo.invalidExternalMaps, importMapUrl) | ||
return promise.then( | ||
() => !includes(imo.invalidExternalMaps, importMapUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no issue about this. The power of unit tests 🙂
src/api/localStorageMock.js
Outdated
@@ -0,0 +1,25 @@ | |||
// Mocks for the localStorage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another left over from the many reopenings of this PR. Sorry about this. Removed.
For automated publishing to work, @joeldenning, before merging it is necessary that:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, one last comment
src/server/server-api.js
Outdated
@@ -1,4 +1,4 @@ | |||
import cookie from "cookie"; | |||
const cookie = require("cookie"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am hesitant about this change because it could impact a lot of things (bundling, tests, linter, etc). All ESM is better.
I read through the rollup documentation linked to in the warning you shared (https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) and the solution seems to be to add @rollup/plugin-node-resolve
rather than to change it to a CJS import. Is there an error even when rollup node resolve is present?
Have you tested that import-map-overrides works server-side after this change?
To unblock this PR I have reverted all changes related to the warning I get when building |
This PR:
For automated publishing to work, it is necessary that:
GITHUB_TOKEN
is granted permissions to create and approve pull requests. This can be done inSettings
->Actions
->General
->Workflow permissions
->Allow GitHub Actions to create and approve pull requests
NPM_TOKEN
secret with an NPM token with write permissions to the organization (or at least the corresponding package, for publishing).