Skip to content

Commit

Permalink
Merge branch 'tact-lang:main' into ternary-operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich authored Nov 29, 2023
2 parents 2e1789a + 53d68b3 commit a2b50d1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Node.js CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

strategy:
fail-fast: false
matrix:
node-version: [18.x]
os: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: yarn clean
- run: yarn build
- run: yarn gen
- run: yarn coverage
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"clean": "rm -fr dist",
"build": "tsc && cp ./src/grammar/grammar.ohm* ./dist/grammar/ && cp ./src/func/funcfiftlib.* ./dist/func",
"test": "jest",
"coverage": "COVERAGE=true jest",
"coverage": "cross-env COVERAGE=true jest",
"release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1"
},
"files": [
Expand Down Expand Up @@ -54,6 +54,7 @@
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.11.9",
"@types/qs": "^6.9.7",
"cross-env": "^7.0.3",
"glob": "^8.1.0",
"jest": "^29.3.1",
"js-yaml": "^4.1.0",
Expand Down
9 changes: 5 additions & 4 deletions scripts/pack.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import fs from 'fs';
import path from 'path';
import glob from 'glob';
import { posixNormalize } from '../src/utils/filePath';

// Pack func
let wasmBase64 = fs.readFileSync(path.resolve(__dirname, '..', 'src', 'func', 'funcfiftlib.wasm')).toString('base64');
let wasmBase64js = `module.exports = { FuncFiftLibWasm: '${wasmBase64}' };`;
fs.writeFileSync(path.resolve(__dirname, '..', 'src', 'func', 'funcfiftlib.wasm.js'), wasmBase64js);

// Pack stdlib
let t = glob.sync(path.resolve(__dirname, '..', 'stdlib', '**', '*.@(tact|fc)'));
let stdlibFiles = glob.sync(path.resolve(__dirname, '..', 'stdlib', '**', '*.@(tact|fc)'), {windowsPathsNoEscape: true});
const dirPrefixToRemove = posixNormalize(path.resolve(__dirname, '..', 'stdlib')) + '/'; // Remove also the leading slash
let output: string = '';
output = 'let files: { [key: string]: string } = {};\n';
for (let f of t) {
for (let f of stdlibFiles) {
let code = fs.readFileSync(f).toString('base64');
let name = f.replace(path.resolve(__dirname, '..', 'stdlib'), ''); // Thanks ChatGPT
name = name.slice(1); // Remove leading slash
let name = f.replace(dirPrefixToRemove, '');
output += `files['${name}'] =\n`;
let first = true;
while (code.length > 0) {
Expand Down
14 changes: 1 addition & 13 deletions src/pipeline/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,13 @@ import { packageCode } from '../packaging/packageCode';
import { createABITypeRefFromTypeRef } from '../types/resolveABITypeRef';
import { getContracts, getType } from '../types/resolveDescriptors';
import { errorToString } from '../utils/errorToString';
import { posixNormalize } from '../utils/filePath';
import { createVirtualFileSystem } from '../vfs/createVirtualFileSystem';
import { VirtualFileSystem } from '../vfs/VirtualFileSystem';
import { compile } from './compile';
import { precompile } from "./precompile";
import { getCompilerVersion } from './version';

// ts-ignore is used on purpose here (instead of installing @types/node or similar)
// because the whole package must not depend on any node code
// however, this function is required to fix compilation on windows
function posixNormalize(path: string): string {
// @ts-ignore
if (typeof global === 'object' && typeof global.process === 'object' && typeof global.process.versions === 'object' && global.process.versions.node) {
// @ts-ignore
const pathModule = require('node:path');
return path.split(pathModule.sep).join(pathModule.posix.sep);
}
return path;
}

export async function build(args: {
config: ConfigProject,
project: VirtualFileSystem,
Expand Down
13 changes: 13 additions & 0 deletions src/utils/filePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ts-ignore is used on purpose here (instead of installing @types/node or similar)
// because the whole package must not depend on any node code
// however, this function is required to fix compilation on windows
export function posixNormalize(path: string): string {
// @ts-ignore
if (typeof global === 'object' && typeof global.process === 'object' && typeof global.process.versions === 'object' && global.process.versions.node) {
// @ts-ignore
const pathModule = require('node:path');
let normalized_path = path.split(pathModule.sep).join(pathModule.posix.sep);
return normalized_path;
}
return path;
}
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,14 @@ create-require@^1.1.0:
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

cross-spawn@^7.0.3:
cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
dependencies:
cross-spawn "^7.0.1"

cross-spawn@^7.0.1, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand Down

0 comments on commit a2b50d1

Please sign in to comment.