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

Deps #429

Merged
merged 4 commits into from
Apr 29, 2024
Merged

Deps #429

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

To maintain a high standard of quality in our releases, before merging every pull request we ask that you've completed the following:

- [ ] Forked the repo and created your branch from `master`
- [ ] Forked the repo and created your branch from `main`
- [ ] Made sure tests pass (run `npm it` from the repo root)
- [ ] Expanded test coverage related to your changes:
- [ ] Added and/or updated unit tests (if appropriate)
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
# Go
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -40,7 +40,14 @@ jobs:
- name: Install
run: npm i

- name: Test (Node.js <= 16.x)
if: matrix.node-version <= '16.x'
run: npm run test:nolint
env:
CI: true

- name: Test
if: matrix.node-version > '16.x'
run: npm test
env:
CI: true
Expand All @@ -67,10 +74,10 @@ jobs:
# Go
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: https://registry.npmjs.org/
Expand Down
11 changes: 11 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const arc = require('@architect/eslint-config')

module.exports = [
...arc,
{
ignores: [
'.nyc_output/',
'dist/index.js',
],
},
]
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"lint": "eslint . --fix",
"rc": "npm version prerelease --preid RC",
"test:nolint": "npm run coverage",
"test": "npm run lint && npm run coverage",
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-arc",
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
Expand All @@ -25,16 +26,16 @@
"src/*"
],
"dependencies": {
"@aws-lite/client": "~0.20.0",
"@aws-lite/s3": "^0.1.20"
"@aws-lite/client": "~0.21.1",
"@aws-lite/s3": "^0.1.21"
},
"devDependencies": {
"@architect/eslint-config": "~2.1.2",
"@architect/eslint-config": "~3.0.0",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"cross-env": "7.0.3",
"eslint": "~8.57.0",
"eslint": "~9.1.1",
"mime-types": "~2.1.35",
"mock-tmp": "~0.0.3",
"mock-tmp": "~0.0.4",
"nyc": "~15.1.0",
"proxyquire": "~2.1.3",
"tap-arc": "~1.2.2",
Expand Down
4 changes: 2 additions & 2 deletions src/format/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function compressor (direction, type, data) {
let exec = {
gzip: compress ? gzipSync : gunzipSync,
br: compress ? brotliCompressSync : brotliDecompressSync,
deflate: compress ? deflateSync : inflateSync
deflate: compress ? deflateSync : inflateSync,
}
if (!exec[type]) throw ReferenceError('Invalid compression type specified, must be gzip, br, or deflate')

Expand All @@ -21,5 +21,5 @@ function compressor (direction, type, data) {

module.exports = {
compress: compressor.bind({}, 'compress'),
decompress: compressor.bind({}, 'decompress')
decompress: compressor.bind({}, 'decompress'),
}
6 changes: 3 additions & 3 deletions src/lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
module.exports = {
httpError,
proxyConfig: proxyConfig()
proxyConfig: proxyConfig(),
}

function proxyConfig () {
Expand All @@ -27,7 +27,7 @@ function httpError ({ statusCode = 502, title = 'Unknown error', message = '' })
statusCode,
headers: {
'content-type': 'text/html; charset=utf8;',
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0'
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0',
},
body: `
<!DOCTYPE html>
Expand Down Expand Up @@ -96,6 +96,6 @@ function httpError ({ statusCode = 502, title = 'Unknown error', message = '' })
</div>
</body>
</html>
`
`,
}
}
2 changes: 0 additions & 2 deletions src/lib/get-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ let _s3

module.exports = async function getS3 () {
if (_s3) return _s3
// eslint-disable-next-line
let awsLite = require('@aws-lite/client')
let { s3 } = await awsLite({
region: process.env.AWS_REGION || 'us-west-2',
// eslint-disable-next-line
plugins: [ import('@aws-lite/s3') ],
})
_s3 = s3.GetObject
Expand Down
6 changes: 3 additions & 3 deletions src/read/_pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = async function pretty (params) {
throw err
}
else return {
Body: readFileSync(file)
Body: readFileSync(file),
}
}

Expand Down Expand Up @@ -86,10 +86,10 @@ module.exports = async function pretty (params) {
return {
headers: {
'content-type': 'text/html; charset=utf8;',
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0'
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0',
},
statusCode: 404,
body
body,
}
}
else {
Expand Down
6 changes: 3 additions & 3 deletions src/read/_s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ module.exports = async function readS3 (params) {
statusCode: 302,
headers: {
location,
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0'
}
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0',
},
}
}

Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports = async function readS3 (params) {
headers.etag = IfNoneMatch
response = {
statusCode: 304,
headers
headers,
}
}
else {
Expand Down
1 change: 0 additions & 1 deletion test/unit/src/_methods-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ let asap
function setup () {
delete require.cache[require.resolve(mod)]
delete require.cache[require.resolve(join(mod, 'src', 'read'))]
// eslint-disable-next-line
asap = require(mod)
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit/src/format/response-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ function basicResponse () {
'cache-control': 'max-age=86400',
etag: ETag,
},
body
body,
},
// S3 result object
result: {
ContentType,
ETag,
Body: body
Body: body,
},
Key: 'this-is-fine.gif',
config: { spa: true }
config: { spa: true },
}
}
let htmlKey = 'index.html'
Expand Down
6 changes: 3 additions & 3 deletions test/unit/src/format/templatize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('Templatizer ignores binary responses', t => {
let response = { body: buf(content) }
let result = filePath({
isBinary: true,
response
response,
})
t.equal(content, result.body.toString(), 'Templatizer exited early')
})
Expand All @@ -43,7 +43,7 @@ test('Templatizer replaces fingerprinted assets', t => {
t.plan(6)
let fingerprinted = 'this-is-fine-abc123.gif'
let assets = {
'this-is-fine.gif': fingerprinted
'this-is-fine.gif': fingerprinted,
}
let response = { body: buf('here is an asset: ${STATIC(\'this-is-fine.gif\')}') }
let result = filePath({ response, assets }).body.toString()
Expand All @@ -66,7 +66,7 @@ test('Templatizer replaces fingerprinted assets', t => {
test('Templatizer does not replace fingerprinted assets locally', t => {
t.plan(6)
let assets = {
'this-is-fine.gif': 'this-is-fine-abc123.gif'
'this-is-fine.gif': 'this-is-fine-abc123.gif',
}
let isLocal = true
let response = { body: buf('here is an asset: ${STATIC(\'this-is-fine.gif\')}') }
Expand Down
14 changes: 7 additions & 7 deletions test/unit/src/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let reader = params => params
let readStub = () => reader
let sut = join(process.cwd())
let asap = proxyquire(sut, {
'./read': readStub
'./read': readStub,
})
let { http } = require('@architect/req-res-fixtures')
let reqs = http.req
Expand All @@ -17,7 +17,7 @@ let productionBucket = 'my-production-bucket'
let basicBucketConfig = {
bucket: {
staging: stagingBucket,
}
},
}

test('Set up env', t => {
Expand All @@ -42,8 +42,8 @@ test('Config: bucket', async t => {
// Test ARC_STATIC_BUCKET vs config
proxy = asap({
bucket: {
production: stagingBucket
}
production: stagingBucket,
},
})
result = await proxy(req)
t.equal(result.Bucket, productionBucket, 'ARC_STATIC_BUCKET overrides config')
Expand All @@ -52,8 +52,8 @@ test('Config: bucket', async t => {
// Test config.bucket
proxy = asap({
bucket: {
staging: stagingBucket
}
staging: stagingBucket,
},
})
result = await proxy(req)
t.equal(result.Bucket, stagingBucket, 'config.bucket sets bucket')
Expand Down Expand Up @@ -150,7 +150,7 @@ test('rootPath param', async t => {

let params = proxyReq
params.requestContext = {
path: '/staging/nature/hiking'
path: '/staging/nature/hiking',
}
result = await proxy(proxyReq)
t.equal(result.rootPath, 'staging', 'rootPath param correctly set: staging')
Expand Down
23 changes: 11 additions & 12 deletions test/unit/src/read/_local-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ let setSandboxPath = tmp => sandboxPath = join(tmp, public)
// static.json
let staticStub = {
'images/this-is-fine.gif': 'images/this-is-fine-a1c3e5.gif',
'publicfile.md': 'publicfile-b2d4f6.md'
'publicfile.md': 'publicfile-b2d4f6.md',
}
// eslint-disable-next-line
let prettyStub = async () => 'pretty'

// Generates proxy read requests
Expand All @@ -30,7 +29,7 @@ function read (params = {}) {
return {
Key: Key || 'images/this-is-fine.gif',
IfNoneMatch: IfNoneMatch || 'abc123',
config: config || { spa: true, sandboxPath }
config: config || { spa: true, sandboxPath },
}
}

Expand All @@ -52,10 +51,10 @@ let imgETag = hash(imgContents)
let binary = [
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13,
73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1,
8, 4, 0, 0, 0, 181, 28, 12, 2, 0, 0, 0,
8, 4, 0, 0, 0, 181, 28, 12, 2, 0, 0, 0,
11, 73, 68, 65, 84, 120, 218, 99, 100, 96, 0, 0,
0, 6, 0, 2, 48, 129, 208, 47, 0, 0, 0, 0,
73, 69, 78, 68, 174, 66, 96, 130
0, 6, 0, 2, 48, 129, 208, 47, 0, 0, 0, 0,
73, 69, 78, 68, 174, 66, 96, 130,
]

let mdName = 'some-file.md'
Expand All @@ -66,7 +65,7 @@ let defaultCacheControl = 'public, max-age=0, must-revalidate'
// Ok, we're good to go
let sut = join(process.cwd(), 'src', 'read', '_local')
let readLocal = proxyquire(sut, {
'./_pretty': prettyStub
'./_pretty': prettyStub,
})

test('Set up env', t => {
Expand All @@ -77,7 +76,7 @@ test('Set up env', t => {
test('Local proxy reader returns formatted response from text payload (200)', async t => {
t.plan(6)
let tmp = mockTmp({
[join(public, imgName)]: imgContents
[join(public, imgName)]: imgContents,
})
setSandboxPath(tmp)
let result = await readLocal(read())
Expand All @@ -93,7 +92,7 @@ test('Local proxy reader returns formatted response from text payload (200)', as
test('Local proxy reader returns formatted response from binary payload (200)', async t => {
t.plan(2)
let tmp = mockTmp({
[join(public, imgName)]: Buffer.from(binary)
[join(public, imgName)]: Buffer.from(binary),
})
setSandboxPath(tmp)
let result = await readLocal(read())
Expand All @@ -109,7 +108,7 @@ test('Local proxy reader unsets ARC_STATIC_PREFIX and returns formatted response
t.ok(process.env.ARC_STATIC_PREFIX, 'ARC_STATIC_PREFIX set')

let tmp = mockTmp({
[join(public, imgName)]: imgContents
[join(public, imgName)]: imgContents,
})
setSandboxPath(tmp)
let params = read({ Key: `${process.env.ARC_STATIC_PREFIX}/${imgName}` })
Expand All @@ -127,7 +126,7 @@ test('Local proxy reader unsets ARC_STATIC_PREFIX and returns formatted response
test('Local proxy reader returns 304 (aka S3 NotModified)', async t => {
t.plan(2)
let tmp = mockTmp({
[join(public, imgName)]: imgContents
[join(public, imgName)]: imgContents,
})
setSandboxPath(tmp)
let params = read({ IfNoneMatch: hash(imgContents) })
Expand All @@ -143,7 +142,7 @@ test('Local proxy reader templatizes with local paths when fingerprinting is ena
process.env.ARC_ENV = 'staging'
let tmp = mockTmp({
[join(public, mdName)]: mdContents,
[join(public, imgName)]: imgContents
[join(public, imgName)]: imgContents,
})
setSandboxPath(tmp)
let params = read({ Key: mdName, config: { assets: staticStub, sandboxPath } })
Expand Down
Loading