Skip to content

Commit

Permalink
change to yarn and type module
Browse files Browse the repository at this point in the history
  • Loading branch information
lagden committed May 4, 2021
1 parent 328ac31 commit 24cb14e
Show file tree
Hide file tree
Showing 15 changed files with 7,523 additions and 18,982 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- run: npm ci
- run: yarn set version berry
- run: >
echo 'nodeLinker: node-modules' >> .yarnrc.yml
- run: yarn install
- run: npm test
env:
CI: true
Expand Down
50 changes: 15 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
dist/*
# node
node_modules

# Yarn
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
!.yarnrc.yml
.pnp.*

# Logs
logs
*.log
npm-debug.log*
*.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
# Coverage
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
*.lcov
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ Codepen example: https://codepen.io/lagden/pen/QWGzRXZ?editors=1010
<button type="button" id="downloadFile">Download</button>

<script type="module">
import {download} from 'https://unpkg.com/@tadashi/fd@1.0.0/src/index.js'
import {download} from 'https://unpkg.com/@tadashi/fd@{version}/src/download.js'
async function getFile(url, filename) {
const response = await globalThis.fetch(url)
await download(response, filename)
}
downloadFile.addEventListener('click', async () => {
await getFile('https://api.mocki.io/v1/871ab1d2', 'foo.json')
await getFile('https://mocki.io/v1/d4867d8b-b5d5-4a48-a4ab-79131b5809b8', 'foo.json')
})
</script>
```
Expand Down
40 changes: 0 additions & 40 deletions bin/_fn
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,3 @@ abort() {
ok() {
printf "\n \033[32mOk: $@\033[0m\n\n"
}

load_env() {
_DIR="$(pwd)"
ENVFILE_BASE="${2:-$_DIR}/.env-base"
ENVFILE_LOCAL="${2:-$_DIR}/.env-local"
ENVFILE_OPT="${2:-$_DIR}/.env-${1:-development}"
if test ! -e $ENVFILE_BASE -o ! -e $ENVFILE_OPT; then
abort "Environment file not found"
fi

set -a
. ${ENVFILE_BASE}
. ${ENVFILE_OPT}
set +a

if test -e $ENVFILE_LOCAL; then
set -a
. ${ENVFILE_LOCAL}
set +a
fi
}

gen_env() {
_DIR="$(cd -P "$(dirname "$0")" && pwd)"
GEN_ENV="${2:-$_DIR}/gen_env"

if test -z $1; then
abort "Missing output"
fi

if test ! -f "${GEN_ENV}"; then
abort "File not found: ${GEN_ENV}"
fi

_DIR_FILE=$(dirname "$1")
mkdir -p $_DIR_FILE

$GEN_ENV > $1
ok "ENVs generated... ${1}"
}
66 changes: 0 additions & 66 deletions bin/pkg

This file was deleted.

80 changes: 80 additions & 0 deletions bin/pkg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env node

import path from 'node:path'
import {promises, createWriteStream} from 'node:fs'
import {promisify} from 'node:util'
import child_process from 'node:child_process'

async function read(file, options = {}) {
let filehandle
let content
try {
filehandle = await promises.open(file, 'r')
content = await filehandle.readFile(options)
} finally {
if (filehandle) {
await filehandle.close()
}
}
return content
}

const exec = promisify(child_process.exec)
const packageFile = path.resolve(process.cwd(), 'package.json')
const packageBuf = await read(packageFile)
const packageJson = JSON.parse(packageBuf)

const {
dependencies,
devDependencies
} = packageJson

let cc = 0

function _error(message) {
process.stderr.write(message)
process.exit(1)
}

function getLatestVersionPackage(data, prop) {
if (!data) {
return Promise.resolve('no data to show')
}

const keys = Object.keys(data)
return Promise.allSettled(keys.map(async name => {
const cmd = `npm show ${name} version`
try {
let {stdout: version} = await exec(cmd)
version = String(version).replace('\n', '')
if (version && data[name] !== String(version)) {
cc++
process.stdout.write(`${name} --> ${version}\n`)
packageJson[prop][name] = version
return {name, version}
}
} catch {}
return Promise.reject()
}))
}

try {
await Promise.all([
getLatestVersionPackage(dependencies, 'dependencies'),
getLatestVersionPackage(devDependencies, 'devDependencies')
])

createWriteStream(packageFile)
.on('finish', () => {
process.stdout.write(cc > 0 ? 'All writes are now complete.' : 'No updates')
})
.on('close', () => {
process.exit(0)
})
.on('error', error => {
_error(error.message)
})
.end(JSON.stringify(packageJson, undefined, ' '))
} catch (error) {
_error(error.message)
}
14 changes: 10 additions & 4 deletions bin/zera
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ DIR="$(cd -P "$(dirname "$0")" && pwd)"
CURR_FOLDER="$(pwd)"
cd $CURR_FOLDER

rm -rf "${CURR_FOLDER}/node_modules" "${CURR_FOLDER}/package-lock.json"
npm i
rm -rf \
"${CURR_FOLDER}/node_modules" \
"${CURR_FOLDER}/package-lock.json" \
"${CURR_FOLDER}/yarn.lock" \
"${CURR_FOLDER}/.yarn" \
"${CURR_FOLDER}/.pnp.*"

test $? -ne 0 && abort "NPM Failed" || ok "Zerado..."
yarn install

npm audit fix
test $? -ne 0 && abort "yarn failed" || ok "zerado..."

yarn npm audit

exit 0
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<button type="button" id="downloadFile">Download</button>
<script type="module">
import {download} from '../src/index.js'
import {download} from '../src/download.js'

async function getFile(url, filename) {
const response = await globalThis.fetch(url)
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js → karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = config => {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./src/index.js': ['coverage']
'./src/download.js': ['coverage']
},

// test results reporter to use
Expand Down

0 comments on commit 24cb14e

Please sign in to comment.