mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-07 06:45:23 +02:00
modified
This commit is contained in:
-6
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "script"
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '10'
|
||||
script:
|
||||
- set -e
|
||||
- npm run test
|
||||
- npm run coveralls
|
||||
# after_success:
|
||||
# - git config --global user.email "travis@travis-ci.org"
|
||||
# - git config --global user.name "Travis CI"
|
||||
# - npm config set git-tag-version=false
|
||||
# - NPM_VERSION=$(npm version patch)
|
||||
# - git commit -a -m "${NPM_VERSION:1}" -m "[ci skip]"
|
||||
# - git remote remove origin
|
||||
# - git remote add origin https://${GITHUB_TOKEN}@github.com/xpl/get-source.git
|
||||
# - git push origin HEAD:master
|
||||
# deploy:
|
||||
# provider: npm
|
||||
# email: rocket.mind@gmail.com
|
||||
# api_key:
|
||||
# secure: jEWoCdiL3qadEKV36Aw1On1JNNvzSKIaZELVp0NiQLoWwbnTXzkXJuabHGDUQFnD9VXjhqtduS0GMpaV//HOXalSR72s8+VnnLYxsVj+Aslh1kDEwXW3OsQ2O5PSZY5nmGVYuZVjwFeOa70+cvMd0nE1v9HNgJBhhzeKiewgzusGrGBaW3ovXz9Bf7ITsbkVO55SbW8CroKILrQiPBTSqEUqH0Vx+ucHtb+gfJfOs7kXoCkjf8tu/yZjs5NIaHt1lKoWOmUlG3z7CjtFenieuzlQRe48jSQKnbXh5yJmziKvbiiwEfFnPhzPZqPKiXHDkBOr7Fm+geMSJcbRlu4lhB/aUfDoT5vlabnQsTcxz1wTKW+N/WR2xdl4kc5HPF9Tnx4c/MDVvQnC05NCRtcrtZNAla9r9pG/zmIvmFiP0ulPgDok8+Mq4GrDoNd5T4Dt8Xk+uD+rENjifYNetIU3Zcq7uslkwaoDZq29V/tSdbHVtXjMw+FSbUk5jJxD/4j3FxDaQGjOkjN/kqxcWc1IH5xi9bG0wCD5sKsdadPAuEMCJRFIlRP+EtyLD3CKwFYPKCQuTTvPJnZ6IOtCNGWI4Qe0eYSrmwURIdUkyxUkdeGZhjrTsGtJN7WXKq+JD2JU88978o3ZQ+CN1iqBaL8yhlDt8vhPtkzVqZXWI1LAB9A=
|
||||
env:
|
||||
global:
|
||||
secure: SXc3ilPr7p+uac/b3ibx27zFEuKotjA0FLHkkFaU5Y74Ek++Yh++cmBbXjz8yS2XtaEmvr+EL/Z7cUsD7hbs787+lyc16AJNEf1l3PKwsFx7djsOBdXFf0mVPhmlx2BbAtgrVylPlVM0yzBDUTWOm2lFtMFp8v2vjJeSnePaWV2Gf7T4hpm4S4U0fXeVRFynFIDo+TfyJoNG6zg6iuUcIjiY5zrvE8U6pg3TtRUaQx8+JWZYdukiKEjPZ2mUHHGaHDRouM99wFz7Y1WTBkxYvyIQFNuf9zzJ/IRMFiLMhxPvSbIYHpNtimCWjYL/Hw105BWOxoTOFa2lsRT5dJAxv3LfroWrEG6vnV5BeJ35Ogcy4Mqf0N3lrMjo/vUgbn6nP2MTyADqBjNdJ0T6tqRSY4sE2M0nXddC/9/ONHOnqzOtAxqS72MJ93ZzSJ0VvMIaf2rygAnIHVHe7mzV3EEhs6l5APQYybYWI8bLD8A75LZeBG1tSBvdPdf5ny6l1GSyoQ1qIntfrl/FcGiJKbGVRl6by/XdRIGA9HOenOHdBzLrB58VF0NkOKzmizlu3O51LW21Yt/HwPRAoGb9t/7KAOT6otKplIk8qy/tTzIc0fZm6mG8FmRQsisIrfWTiWh37jSZU9FGdNGkF/tjjZ/bmEPiJ56fWiXvzVv9CQAeF/0=
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Vitaly Gordon (https://github.com/xpl)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
# get-source
|
||||
|
||||
[](https://travis-ci.org/xpl/get-source) [](https://coveralls.io/github/xpl/get-source) [](https://npmjs.com/package/get-source)
|
||||
|
||||
Fetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.
|
||||
|
||||
```bash
|
||||
npm install get-source
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- [x] Allows to read source code files in Node and browsers
|
||||
- [x] Full sourcemap support (path resolving, external/embedded/inline linking, and long chains)
|
||||
- [x] **Synchronous** API — good for CLI tools (e.g. [logging](https://github.com/xpl/ololog)). Works in browsers!
|
||||
- [x] **Asynchronous** API — good for everything web!
|
||||
- [x] Built-in cache
|
||||
|
||||
## What for
|
||||
|
||||
- [x] Call stacks enhanced with source code information (see the [StackTracey](https://github.com/xpl/stacktracey) library)
|
||||
- [x] [Advanced logging](https://github.com/xpl/ololog) / assertion printing
|
||||
- [x] [Error displaying components](https://github.com/xpl/panic-overlay) for front-end web development
|
||||
|
||||
## Usage (Synchronous)
|
||||
|
||||
```javascript
|
||||
import getSource from 'get-source'
|
||||
```
|
||||
```javascript
|
||||
file = getSource ('./scripts/index.min.js')
|
||||
```
|
||||
|
||||
Will read the file synchronously (either via XHR or by filesystem API, depending on the environment) and return it's cached representation. Result will contain the following fields:
|
||||
|
||||
```javascript
|
||||
file.path // normalized file path
|
||||
file.text // text contents
|
||||
file.lines // array of lines
|
||||
```
|
||||
|
||||
And the `resolve` method:
|
||||
|
||||
```javascript
|
||||
file.resolve ({ line: 1, column: 8 }) // indexes here start from 1 (by widely accepted convention). Zero indexes are invalid.
|
||||
```
|
||||
|
||||
It will look through the sourcemap chain, returning following:
|
||||
|
||||
```javascript
|
||||
{
|
||||
line: <original line number>,
|
||||
column: <original column number>,
|
||||
sourceFile: <original source file object>,
|
||||
sourceLine: <original source line text>
|
||||
}
|
||||
```
|
||||
|
||||
In that returned object, `sourceFile` is the same kind of object that `getSource` returns. So you can access its `text`, `lines` and `path` fields to obtain the full information. And the `sourceLine` is returned just for the convenience, as a shortcut.
|
||||
|
||||
## Usage (Asynchronous)
|
||||
|
||||
Pretty much the same as synchronous, except it's `getSource.async`. It returns awaitable promises:
|
||||
|
||||
```javascript
|
||||
file = await getSource.async ('./scripts/index.min.js')
|
||||
location = await file.resolve ({ line: 1, column: 8 })
|
||||
```
|
||||
|
||||
## Error handling
|
||||
|
||||
In synchronous mode, it never throws (due to backward compatibility reasons with existing code):
|
||||
|
||||
```javascript
|
||||
nonsense = getSource ('/some/nonexistent/file')
|
||||
|
||||
nonsense.text // should be '' (so it's safe to access without checking)
|
||||
nonsense.error // should be an Error object, representing an actual error thrown during reading/parsing
|
||||
```
|
||||
```javascript
|
||||
resolved = nonsense.resolve ({ line: 5, column: 0 })
|
||||
|
||||
resolved.sourceLine // empty string (so it's safe to access without checking)
|
||||
resolved.error // should be an Error object, representing an actual error thrown during reading/parsing
|
||||
```
|
||||
|
||||
In asychronous mode, it throws an error:
|
||||
|
||||
```javascript
|
||||
try {
|
||||
file = await getSource.async ('/some/file')
|
||||
location = await file.resolve ({ line: 5, column: 0 })
|
||||
} catch (e) {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Resetting Cache
|
||||
|
||||
E.g. when you need to force-reload files:
|
||||
|
||||
```javascript
|
||||
getSource.resetCache () // sync cache
|
||||
getSource.async.resetCache () // async cache
|
||||
```
|
||||
|
||||
Also, viewing cached files:
|
||||
|
||||
```javascript
|
||||
getSource.getCache () // sync cache
|
||||
getSource.async.getCache () // async cache
|
||||
```
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
|
||||
declare interface Location {
|
||||
|
||||
line: number;
|
||||
column: number;
|
||||
}
|
||||
|
||||
declare interface ResolvedLocation<FileType> extends Location {
|
||||
|
||||
sourceFile: FileType;
|
||||
sourceLine: string;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
declare interface File {
|
||||
|
||||
path: string;
|
||||
text: string;
|
||||
lines: string[];
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
declare interface FileAsync extends File {
|
||||
resolve (location: Location): Promise<ResolvedLocation<FileAsync>>
|
||||
}
|
||||
|
||||
declare interface FileSync extends File {
|
||||
resolve (location: Location): ResolvedLocation<FileSync>
|
||||
}
|
||||
|
||||
declare interface FileCache<T> {
|
||||
|
||||
resetCache (): void;
|
||||
getCache (): { [key: string]: T };
|
||||
}
|
||||
|
||||
declare interface getSourceAsync extends FileCache<FileAsync> {
|
||||
(path: string): Promise<FileAsync>;
|
||||
}
|
||||
|
||||
declare interface getSourceSync extends FileCache<FileSync> {
|
||||
(path: string): FileSync;
|
||||
async: getSourceAsync;
|
||||
}
|
||||
|
||||
declare const getSource: getSourceSync;
|
||||
|
||||
export = getSource;
|
||||
-176
@@ -1,176 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
const { assign } = Object,
|
||||
isBrowser = (typeof window !== 'undefined') && (window.window === window) && window.navigator,
|
||||
SourceMapConsumer = require ('source-map').SourceMapConsumer,
|
||||
SyncPromise = require ('./impl/SyncPromise'),
|
||||
path = require ('./impl/path'),
|
||||
dataURIToBuffer = require ('data-uri-to-buffer'),
|
||||
nodeRequire = isBrowser ? null : module.require
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
const memoize = f => {
|
||||
|
||||
const m = x => (x in m.cache) ? m.cache[x] : (m.cache[x] = f(x))
|
||||
m.forgetEverything = () => { m.cache = Object.create (null) }
|
||||
m.cache = Object.create (null)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
function impl (fetchFile, sync) {
|
||||
|
||||
const PromiseImpl = sync ? SyncPromise : Promise
|
||||
const SourceFileMemoized = memoize (path => SourceFile (path, fetchFile (path)))
|
||||
|
||||
function SourceFile (srcPath, text) {
|
||||
if (text === undefined) return SourceFileMemoized (path.resolve (srcPath))
|
||||
|
||||
return PromiseImpl.resolve (text).then (text => {
|
||||
|
||||
let file
|
||||
let lines
|
||||
let resolver
|
||||
let _resolve = loc => (resolver = resolver || SourceMapResolverFromFetchedFile (file)) (loc)
|
||||
|
||||
return (file = {
|
||||
path: srcPath,
|
||||
text,
|
||||
get lines () { return lines = (lines || text.split ('\n')) },
|
||||
resolve (loc) {
|
||||
const result = _resolve (loc)
|
||||
if (sync) {
|
||||
try { return SyncPromise.valueFrom (result) }
|
||||
catch (e) { return assign ({}, loc, { error: e }) }
|
||||
} else {
|
||||
return Promise.resolve (result)
|
||||
}
|
||||
},
|
||||
_resolve,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function SourceMapResolverFromFetchedFile (file) {
|
||||
|
||||
/* Extract the last sourceMap occurence (TODO: support multiple sourcemaps) */
|
||||
|
||||
const re = /\u0023 sourceMappingURL=(.+)\n?/g
|
||||
let lastMatch = undefined
|
||||
|
||||
while (true) {
|
||||
const match = re.exec (file.text)
|
||||
if (match) lastMatch = match
|
||||
else break
|
||||
}
|
||||
|
||||
const url = lastMatch && lastMatch[1]
|
||||
|
||||
const defaultResolver = loc => assign ({}, loc, {
|
||||
sourceFile: file,
|
||||
sourceLine: (file.lines[loc.line - 1] || '')
|
||||
})
|
||||
|
||||
return url ? SourceMapResolver (file.path, url, defaultResolver)
|
||||
: defaultResolver
|
||||
}
|
||||
|
||||
function SourceMapResolver (originalFilePath, sourceMapPath, fallbackResolve) {
|
||||
|
||||
const srcFile = sourceMapPath.startsWith ('data:')
|
||||
? SourceFile (originalFilePath, dataURIToBuffer (sourceMapPath).toString ())
|
||||
: SourceFile (path.relativeToFile (originalFilePath, sourceMapPath))
|
||||
|
||||
const parsedMap = srcFile.then (f => SourceMapConsumer (JSON.parse (f.text)))
|
||||
|
||||
const sourceFor = memoize (function sourceFor (filePath) {
|
||||
return srcFile.then (f => {
|
||||
const fullPath = path.relativeToFile (f.path, filePath)
|
||||
return parsedMap.then (x => SourceFile (
|
||||
fullPath,
|
||||
x.sourceContentFor (filePath, true /* return null on missing */) || undefined))
|
||||
})
|
||||
})
|
||||
|
||||
return loc => parsedMap.then (x => {
|
||||
const originalLoc = x.originalPositionFor (loc)
|
||||
return originalLoc.source ? sourceFor (originalLoc.source).then (x =>
|
||||
x._resolve (assign ({}, loc, {
|
||||
line: originalLoc.line,
|
||||
column: originalLoc.column + 1,
|
||||
name: originalLoc.name
|
||||
}))
|
||||
)
|
||||
: fallbackResolve (loc)
|
||||
}).catch (e =>
|
||||
assign (fallbackResolve (loc), { sourceMapError: e }))
|
||||
}
|
||||
|
||||
return assign (function getSource (path) {
|
||||
const file = SourceFile (path)
|
||||
if (sync) {
|
||||
try { return SyncPromise.valueFrom (file) }
|
||||
catch (e) {
|
||||
const noFile = {
|
||||
path,
|
||||
text: '',
|
||||
lines: [],
|
||||
error: e,
|
||||
resolve (loc) {
|
||||
return assign ({}, loc, { error: e, sourceLine: '', sourceFile: noFile })
|
||||
}
|
||||
}
|
||||
return noFile
|
||||
}
|
||||
}
|
||||
return file
|
||||
}, {
|
||||
resetCache: () => SourceFileMemoized.forgetEverything (),
|
||||
getCache: () => SourceFileMemoized.cache
|
||||
})
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
module.exports = impl (function fetchFileSync (path) {
|
||||
return new SyncPromise (resolve => {
|
||||
if (isBrowser) {
|
||||
let xhr = new XMLHttpRequest ()
|
||||
xhr.open ('GET', path, false /* SYNCHRONOUS XHR FTW :) */)
|
||||
xhr.send (null)
|
||||
resolve (xhr.responseText)
|
||||
} else {
|
||||
resolve (nodeRequire ('fs').readFileSync (path, { encoding: 'utf8' }))
|
||||
}
|
||||
})
|
||||
}, true)
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
module.exports.async = impl (function fetchFileAsync (path) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
if (isBrowser) {
|
||||
let xhr = new XMLHttpRequest ()
|
||||
xhr.open ('GET', path)
|
||||
xhr.onreadystatechange = event => {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
resolve (xhr.responseText)
|
||||
} else {
|
||||
reject (new Error (xhr.statusText))
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.send (null)
|
||||
} else {
|
||||
nodeRequire ('fs').readFile (path, { encoding: 'utf8' }, (e, x) => {
|
||||
e ? reject (e) : resolve (x)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
{
|
||||
"name": "get-source",
|
||||
"version": "2.0.12",
|
||||
"description": "Fetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.",
|
||||
"main": "get-source",
|
||||
"types": "./get-source.d.ts",
|
||||
"scripts": {
|
||||
"test-browser": "mocha test/test.browser --reporter spec",
|
||||
"test-node": "mocha test/test.node --reporter spec",
|
||||
"test-path": "mocha test/test.path --reporter spec",
|
||||
"test": "nyc --reporter=html --reporter=text mocha test/test.path test/test.node --reporter spec",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/xpl/get-source.git"
|
||||
},
|
||||
"keywords": [
|
||||
"sources",
|
||||
"sourcemap",
|
||||
"read source",
|
||||
"cached sources"
|
||||
],
|
||||
"author": "Vitaly Gordon <rocket.mind@gmail.com>",
|
||||
"license": "Unlicense",
|
||||
"bugs": {
|
||||
"url": "https://github.com/xpl/get-source/issues"
|
||||
},
|
||||
"homepage": "https://github.com/xpl/get-source",
|
||||
"devDependencies": {
|
||||
"chai": "^3.5.0",
|
||||
"coveralls": "^3.0.3",
|
||||
"istanbul": "^0.4.5",
|
||||
"memory-fs": "^0.3.0",
|
||||
"mocha": "^8.0.1",
|
||||
"nyc": "^15.1.0",
|
||||
"webpack": "^4.43.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"data-uri-to-buffer": "^2.0.0",
|
||||
"source-map": "^0.6.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user