aws-lite icon indicating copy to clipboard operation
aws-lite copied to clipboard

Deno + JSR support

Open ryanblock opened this issue 11 months ago • 0 comments

Did some investigating into Deno + JSR support. The Node.js compatibility is pretty excellent right now, although testing the module required some workarounds. (We now have a related open issue with Deno.)

Checklist so far:

  • [x] Port test suite to ESM (https://github.com/architect/aws-lite/commit/d697aba9329a740f5ffb4a1d445151c84104a5b2)
  • [x] Add node: specifiers to require / import calls (https://github.com/architect/aws-lite/commit/e0545c00384e58ffe26af07e1bfeca60427229f9)
  • [x] Implement node_modules workarounds to get Deno running tests (https://github.com/architect/aws-lite/commit/b0166926b367dbab576e5ab2b812a2d345035ce5)
    • Some tests are running, but will require a variety of small conditional changes
  • [ ] Update tests to run against Deno
  • [ ] Investigation into HTTP error states to ensure retries work properly
  • [ ] Add JSR entry file
  • [ ] Implement jsr.json / deno.json for root package; handle import maps, etc.
  • [ ] Implement jsr.json / deno.json for all plugins
  • [ ] Update plugin generation scripts to include jsr.json / deno.json files
  • [ ] Update CI to publish client to JSR
  • [ ] Update plugin publisher to publish to JSR

A couple (internal) notes:

JSR entry file (something like this):

import aws from 'npm:@aws-lite/[email protected]'
export let awsLite = aws

We'll need to add some occasional environment switching like so:

function isNode () {
  try { return !(Deno.env) }
  catch { return true }
}

Various tests will wind up needing environment-specific client instantiation like so:

test('Set up env', async t => {
  t.plan(1)
  if (isNode()) {
    let cwd = process.cwd()
    let sut = 'file://' + join(cwd, 'src', 'index.js')
    client = (await import(sut)).default
  }
  else {
    client = (await import('npm:@aws-lite/client')).default
  }
  t.ok(client, 'aws-lite client is present')
})

AWS test lib will need some updates as well, like:

let awsEnvVars = [
  'AMAZON_REGION',
  'AWS_ACCESS_KEY',
  'AWS_ACCESS_KEY_ID',
  'AWS_CONFIG_FILE',
  'AWS_DEFAULT_REGION',
  'AWS_ENDPOINT_URL',
  'AWS_LAMBDA_FUNCTION_NAME',
  'AWS_PROFILE',
  'AWS_REGION',
  'AWS_SDK_LOAD_CONFIG',
  'AWS_SECRET_ACCESS_KEY',
  'AWS_SECRET_KEY',
  'AWS_SESSION_TOKEN',
  'AWS_SHARED_CREDENTIALS_FILE',
]
function resetAWSEnvVars () {
  awsEnvVars.forEach(envVar => {
    if (isNode()) delete process.env[envVar]
    else Deno.env.delete(envVar)
  })

Tests checking Node's ECONNREFUSED get replaced with /\@aws-lite\/client: lambda: error sending request/

ryanblock avatar Mar 04 '24 18:03 ryanblock