1.1.4 • Published 7 months ago

globusa v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

globusa

npm.io

Globusa exports one function, parse(), that takes a string of javascript code and returns an object that looks like this:

{
  imports: [],               // mitosis-style import objects
  declarations: [],          // strings
  exports: [],               // strings
  domqlComponents: [],       // [ { name: null/string, code: string }, ... ]
  linesExcludingImports: [], //
  identifiers: [],           // strings
}

At its core, globusa handles the global scope in a javascript file that exports domql components so that the component can easily be converted to other frameworks using Kalduna.

Basically, with the help of Globusa, Kalduna can convert something like this:

import { Text } from '@symbo.ls/atoms'
import { someFunction } from './Atoms/Flex'

const localFn = (a,b) => a + b

export const Title = {
  extend: Text,
  style: { fontSize: '55px' },
  on: { click: (ev, el) => { console.log(someFunction(ev), localFn(1, 2)) } }
}

Into this: (notice the imports and the localFn declaration)

import { Text } from '@symbo.ls/atoms' // Kalduna will include this
import { someFunction } from './Atoms/Flex' // Included by globusa

const localFn = (a,b) => a + b // Copied by globusa

export default function Title(props) {
  const el = {
    props: ...
    parent: ...
    ...
  }

  function Text_onClick(ev, el) {
    console.log(someFunction(ev), localFn(1, 2))
  }

  return (
    <Text
      style={`${css({ fontSize: '55px' })}`)
      onClick={(ev) => Text_onClick(ev, el)}
      ...props />
  )
}

Tests

The testing scheme is based off of Kalduna's testing scheme.

We use node's built-in assertion module instead of a separate library.

How to run tests

To run the entire test suite, do yarn test from the root of this repository.

To run only specific tests, simply pass a file name or pattern to the script:

yarn test dedup-mitosis-imports.test.js
# or
yarn test dedup*.test.js

How it works

  • tests/esbuild-tests.js compiles all the .test.js files from tests/ and puts them in tests/dist/.
  • Each compiled test suite file in tests/dist/ is run with node as a separate process so that if a crash happens in one suite, it doesn't affect the other ones.
  • If no errors show up during testing then all tests have passeed.
1.1.1

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.0

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago