Skip to content

refactor: Add TypeScript support #1985

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

Merged
merged 14 commits into from
Aug 14, 2023
Merged
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ jobs:
uses: mansona/npm-lockfile-version@v1
with:
version: 2
check-types:
name: Check types
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
- name: Check types
run: npm run test:types
build:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down
2 changes: 1 addition & 1 deletion babel-jest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const babelJest = require('babel-jest');

module.exports = babelJest.createTransformer({
presets: [["@babel/preset-env", {
presets: ["@babel/preset-typescript", ["@babel/preset-env", {
"targets": {
"node": "14"
},
Expand Down
14 changes: 7 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ const transformRuntime = ["@babel/plugin-transform-runtime", {
}];

const PRESETS = {
'browser': [["@babel/preset-env", {
'browser': ["@babel/preset-typescript", ["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}]],
'weapp': [["@babel/preset-env", {
'weapp': ["@babel/preset-typescript", ["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}], '@babel/react'],
'node': [["@babel/preset-env", {
'node': ["@babel/preset-typescript", ["@babel/preset-env", {
"targets": { "node": "14" }
}]],
'react-native': ['module:metro-react-native-babel-preset'],
'react-native': ["@babel/preset-typescript", 'module:metro-react-native-babel-preset'],
};
const PLUGINS = {
'browser': [transformRuntime, '@babel/plugin-transform-flow-comments', '@babel/plugin-proposal-class-properties', 'inline-package-json',
Expand Down Expand Up @@ -79,7 +79,7 @@ function compileTask(stream) {
}

gulp.task('compile', function() {
return compileTask(gulp.src('src/*.js'));
return compileTask(gulp.src('src/*.*(js|ts)'));
});

gulp.task('browserify', function(cb) {
Expand Down Expand Up @@ -137,7 +137,7 @@ gulp.task('minify-weapp', function() {

gulp.task('watch', function() {
if (BUILD === 'browser') {
const watcher = gulp.watch('src/*.js', { ignoreInitial: false }, gulp.series('compile', 'browserify', 'minify'));
const watcher = gulp.watch('src/*.*(js|ts)', { ignoreInitial: false }, gulp.series('compile', 'browserify', 'minify'));
watcher.on('add', function(path) {
console.log(`File ${path} was added`);
});
Expand All @@ -146,5 +146,5 @@ gulp.task('watch', function() {
});
return watcher;
}
return compileTask(watch('src/*.js', { ignoreInitial: false, verbose: true }));
return compileTask(watch('src/*.*(js|ts)', { ignoreInitial: false, verbose: true }));
});
2,461 changes: 2,276 additions & 185 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"@babel/plugin-transform-runtime": "7.21.4",
"@babel/preset-env": "7.21.5",
"@babel/preset-react": "7.22.5",
"@babel/preset-typescript": "7.22.5",
"@definitelytyped/dtslint": "0.0.163",
"@parse/minami": "1.0.0",
"@saithodev/semantic-release-backmerge": "2.1.3",
"@semantic-release/changelog": "6.0.3",
Expand Down Expand Up @@ -95,10 +97,12 @@
},
"scripts": {
"build": "node build_releases.js",
"build:types": "tsc",
"release": "node build_releases.js && npm publish",
"test": "cross-env PARSE_BUILD=node jest",
"test:mongodb": "npm run test:mongodb:runnerstart && npm run integration",
"test:mongodb:runnerstart": "mongodb-runner start -- --port 27017",
"test:types": "dtslint --expectOnly types",
"posttest:mongodb": "mongodb-runner stop --all",
"lint": "eslint --cache src/ integration/",
"lint:fix": "eslint --fix --cache src/ integration/",
Expand Down
5 changes: 4 additions & 1 deletion src/CoreManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function requireMethods(name: string, methods: Array<string>, controller: any) {
});
}

module.exports = {
const CoreManager = {
get: function (key: string): any {
if (config.hasOwnProperty(key)) {
return config[key];
Expand Down Expand Up @@ -468,3 +468,6 @@ module.exports = {
return config['HooksController'];
},
};

module.exports = CoreManager;
export default CoreManager;
1 change: 1 addition & 0 deletions src/EventuallyQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,4 @@ const EventuallyQueue = {
};

module.exports = EventuallyQueue;
export default EventuallyQueue;
1 change: 1 addition & 0 deletions src/LocalDatastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ const LocalDatastore = {
};

module.exports = LocalDatastore;
export default LocalDatastore;

if (process.env.PARSE_BUILD === 'react-native') {
CoreManager.setLocalDatastoreController(require('./LocalDatastoreController.react-native'));
Expand Down
Loading