-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
install a svelte-kit package from git #2772
Comments
I have a hunch that the solution to this will overlap with #2242, though I don't have a clear idea off the top of my head what the best answer is |
closed accidentally |
not really ... here: fix the production environment for "install from git" there: fix the development environment, work with typescript files |
Can this be solved already by creating a manual exports map in the package.json of the project?
|
i still think its easier to emulate alternative solution: "svelte": "index.js",
"module": "dist/jsoneditor.js",
"main": "dist/jsoneditor.js", to "svelte": "package/index.js",
"module": "package/dist/jsoneditor.js",
"main": "package/dist/jsoneditor.js", by running this after #! /usr/bin/env node
import fs from 'fs'
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
for (const key of ['svelte', 'module', 'main']) {
if (!pkg[key]) continue
// workaround: avoid double-patching
// FIXME why is this script called twice
if (pkg[key].startsWith('package/')) continue
pkg[key] = 'package/' + pkg[key]
}
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n', 'utf8') example https://github.com/milahu/svelte-jsoneditor/tree/fix-install-from-git-3 problem is, i also tried "exports": { ".": "package/index.js" }, and "exports": { "./*": "package/*" }, ... but then npm is deleting the generated files in in reproducecd $(mktemp -d)
git clone --depth 1 https://github.com/sveltejs/template/ svelte-project
cd svelte-project
npm install
cat >src/App.svelte <<'EOF'
<script>
import { JSONEditor } from 'svelte-jsoneditor'
let content = {
text: undefined, // used when in code mode
json: { array: [1, 2, 3] }
}
</script>
<div>
<JSONEditor bind:content />
</div>
EOF
# fix rollup: [!] Error: Invalid value "iife" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.
sed -i "s|format: 'iife',|//&|" rollup.config.js
sed -i "s|file: 'public/build/bundle.js'|dir: 'public/build'|" rollup.config.js
sed -i "s|/bundle.js'|/main.js' type='module'|" public/index.html
npm add -D https://github.com/josdejong/svelte-jsoneditor
npm run dev
# Error: Could not load node_modules/svelte-jsoneditor/index.js (imported by src/App.svelte): ENOENT: no such file or directory
# problem: `build` script was not run in `prepare`
# install from git: run `build` in `prepare`
# note: with npm, build takes about four minutes, also because of typescript typechecking
# svelte-kit: 20 seconds
# rollup: 80 seconds - with esbuild: 40 seconds
# version 2: move ./package/* files to ./
npm rm svelte-jsoneditor # force re-install
npm add -D https://github.com/milahu/svelte-jsoneditor#fix-install-from-git-2
npm run dev
# version 3: patch paths in package.json
npm rm svelte-jsoneditor # force re-install
npm add -D https://github.com/milahu/svelte-jsoneditor#fix-install-from-git-3
npm run dev |
I think this may have been solved by #8922 |
Describe the problem
when creating packages with svelte-kit https://kit.svelte.dev/docs#packaging
how is this supposed to work, when i install the package from git?
for example: svelte-jsoneditor
usually i use the "prepare" script in package.json, to build such a library
but when the build is written to
node_modules/pname/package/package.json
then obviously i cannot import it via
node_modules/pname/package.json
Describe the proposed solution
naive solution: in svelte.config.js set
kit.package.dir = "."
but this will delete the project root folder, including
.git
workaround:
in svelte.config.js set
kit.package.dir = "package"
package.json
svelte.prepare.mjs
old version: svelte.prepare.sh
Alternatives considered
No response
Importance
i cannot use SvelteKit without it
(no seriously, "install from git" is a standard feature of npm)
Additional Information
No response
The text was updated successfully, but these errors were encountered: