[go: nahoru, domu]

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

docs: add deno example #678

Merged
merged 8 commits into from
Dec 1, 2022
Merged

Conversation

johnhooks
Copy link
Contributor
@johnhooks johnhooks commented Nov 23, 2022

I've been playing with using Dinero.js with Deno. It requires using an import map. I thought an example might be helpful.

I will need to figure out how to change the version numbers in the import_map.json. I also don't know if for the example the deno.lock file should be committed.

The example has the exact same contents as example/starter.

@vercel
Copy link
vercel bot commented Nov 23, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
dinerojs ✅ Ready (Inspect) Visit Preview Nov 30, 2022 at 1:55PM (UTC)

@codesandbox-ci
Copy link
codesandbox-ci bot commented Nov 23, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6ff5ff9:

Sandbox Source
@dinero.js/example-cart-react Configuration
@dinero.js/example-cart-vue Configuration
@dinero.js/example-pricing-react Configuration
@dinero.js/example-starter Configuration

@sarahdayan
Copy link
Collaborator
sarahdayan commented Nov 23, 2022

Neat! I've pushed some slight changes to use npm specifiers, this way there's no need for import maps.

I also don't know if for the example the deno.lock file should be committed.

Yes, committing it is a good call as it stores and checks subresource integrity. There are no lock files in the other examples because they're all in the yarn.lock file at the root of the monorepo, but dependencies are locked too.

@johnhooks
Copy link
Contributor Author

@sarahdayan I forgot about the npm specifier, thanks! That is cleaner.

@sarahdayan
Copy link
Collaborator

@johnhooks Not natively. We need to use a package.json file and install Deno (see example here).

I think it's fine not to do it.

@sarahdayan
Copy link
Collaborator

One thing to figure out before moving on though is how to make this example play ball with Ship.js and Lerna.

When releasing a new version with Ship.js, once the new version is selected, Lerna runs to update the version of the library everywhere including in the examples (in the package.json). Then, Ship.js runs yarn install which updates yarn.lock, etc.

This won't work out of the box with the Deno example, as I don't think it supports Deno at all.

Maybe one lead is to use relative dependencies instead of npm specifiers?

@johnhooks
Copy link
Contributor Author

That works if someone downloads the whole repo, but it is confusing if a beginner uses the example as an "example" and copy and pastes.

Maybe relative imports, details in the README.md, a docs page about importing in Deno, and a preemptive GitHub issue or discussion could help solve possible confusion.

@sarahdayan
Copy link
Collaborator

@johnhooks I hoped we could use range versions (@2) but it doesn't appear to be working… maybe because the packages are still alpha?

Another route would be to update this script to update the versions in the example and re-compile the lock file.

@johnhooks
Copy link
Contributor Author

But the lockfile won't update until the packages are published because the aren't available... right?

@johnhooks johnhooks changed the title docs: add deno example with import map docs: add deno example Nov 26, 2022
@johnhooks
Copy link
Contributor Author

I tried the range version with npm:date-fns@2 and it worked. So it probably will work when dinero.js is out of alpha. Though it does add a specific version to the lock file. So it doesn't really fix anything. But it is a rather small issue, especially with such a simple example.

I like the changes you made.

@sarahdayan
Copy link
Collaborator

@johnhooks A simple way to make it work right now could be to leverage the versionUpdated lifecycle of Ship.js to run a small Shell command to replace the version with the new one.

The versionUpdated lifecycle exposes exec so we can use sed with a regular expression to find the current version and replace it with the exposed version.

@johnhooks
Copy link
Contributor Author
johnhooks commented Nov 29, 2022

What I was referring to was the lock file specifically. Unless you want to manually edit it, it can't be updated until after the packages are released. It can probably be cleaned up with a script, but ship.js doesn't have a packagesPublished hook (or I couldn't find it). It looks like there is a hook for Slack, but not a regular hook.

@sarahdayan
Copy link
Collaborator

I forgot that there's sub-resource integrity here 🤦

Another solution is to remove the lock file and exclude it from version control. Users can build it locally. It's only an example, this isn't that big of a deal.

@johnhooks
Copy link
Contributor Author

Another solution is to remove the lock file and exclude it from version control

I think that is simplest

@sarahdayan
Copy link
Collaborator

@johnhooks That works for me, this way we can settle this PR.

@johnhooks
Copy link
Contributor Author
johnhooks commented Nov 30, 2022

@sarahdayan I removed the lock file and rebased to main. It should be ready.

EDIT: Other than it doesn't pass the type check anymore. 77e7f52 added type checking to examples. The npm directives seem to be the culprit, tsc doesn't know what to make of them. Should we ignore just examples/deno, it's really not like anything else in the project, it is supposed to run in a totally different environment.

@sarahdayan
Copy link
Collaborator

@johnhooks Yes let's ignore this example for now. I couldn't find anything related to it in the Deno docs, and I believe npm specifiers are still quite experimental so let's move forward.

@johnhooks
Copy link
Contributor Author

@sarahdayan It should be good now.

Copy link
Collaborator
@sarahdayan sarahdayan left a comment

Choose a reason for hiding this comment

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

Go Deno 🚀

@sarahdayan sarahdayan merged commit 76b11fc into dinerojs:main Dec 1, 2022
@johnhooks johnhooks deleted the add-deno-example branch December 4, 2022 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants