-
Notifications
You must be signed in to change notification settings - Fork 45
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 modules #13
Closed
Closed
Add modules #13
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c62785e
Add .gitignore. Ignore node_modules, dist and .tmp dirs
darcyparker 4490b40
package.json: Add package.json
darcyparker a6da303
rollup.config.js: Simple config to wrap JSONCrush.js in 3 module formats
darcyparker c4a88c3
JSONCrush.d.ts: Typescript definition
darcyparker 0694502
README.md: Update with instructions on using modules
darcyparker File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.tmp | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//Typescript type definitions for JSONCrush | ||
export type JSONCrush = (string: string, maxSubstringLength?: number) => string; | ||
export type JSONUncrush = (string: string) => string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "JSONCrush", | ||
"version": "1.0.1", | ||
"description": "Compress JSON in URL friendly strings", | ||
"main": "dist/JSONCrush.cjs.js", | ||
"module": "dist/JSONCrush.esm.js", | ||
"browser": "dist/JSONCrush.umd.js", | ||
"types": "JSONCrush.d.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "rollup -c", | ||
"preinstall": "npm install --ignore-scripts && npm run build" | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bundle should be built when |
||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/KilledByAPixel/JSONCrush.git" | ||
}, | ||
"keywords": [ | ||
"JSON", | ||
"URL", | ||
"URI", | ||
"compression" | ||
], | ||
"author": "KilledByAPixel", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/KilledByAPixel/JSONCrush/issues" | ||
}, | ||
"homepage": "https://github.com/KilledByAPixel/JSONCrush", | ||
"devDependencies": { | ||
"graceful-fs": "^4.2.4", | ||
"rollup": "^2.36.1" | ||
}, | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pkg from './package.json'; | ||
import * as path from 'path'; | ||
import {readFileSync, writeFileSync, existsSync, mkdirSync} from 'graceful-fs'; | ||
|
||
//Before exporting rollup config: | ||
//* The rollup input requires a statement with exports for modules | ||
//* The input ./JSONCrush.js does not have exports because it may be used in | ||
// contexts that do not support it. (such as ClosureCompiler) | ||
//* This sources JSONCrush.js, appends `exports` statement, and writes result to | ||
// target .tmp/JSONCrush.js | ||
//* Note .tmp is in .gitignore | ||
const inputFileName = 'JSONCrush.js'; | ||
const input = path.join(__dirname, inputFileName); | ||
const tmpDir = path.join(__dirname, '.tmp'); | ||
if (!existsSync(tmpDir)) { mkdirSync(tmpDir); } | ||
const tmpInput = path.join(tmpDir, inputFileName); | ||
writeFileSync(tmpInput, readFileSync(input) + '\nexport {JSONCrush, JSONUncrush};'); | ||
|
||
//Minimal rollup config to wrap JSONCrush in the module types cjs, es and umd | ||
export default { | ||
input: tmpInput, | ||
output: [ | ||
// CommonJS (for Node) | ||
{ file: pkg.main, format: 'cjs' }, | ||
// ES Module | ||
{ file: pkg.module, format: 'es' }, | ||
// browser-friendly UMD build | ||
{ name: 'JSONCrush', file: pkg.browser, format: 'umd' } | ||
] | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Too bad the author didn't claim the
jsoncrush
package name, but overloading via different casing doesn't seem like a great solution here: this will cause problems on filesystems that aren't strictly case-sensitive, e.g. apple filesystem. Are there any known issues with npm installing a namespaced package from a git repo? If not, consider something like@killedbyapixel/jsoncrush
.