Skip to content

Commit

Permalink
Using explicit imports/exports
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Apr 28, 2020
1 parent 494b645 commit 704ef8e
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 34 deletions.
10 changes: 3 additions & 7 deletions gulpfile.cjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
const {spawn} = require('child_process');
const del = require('del');
const {promises} = require('fs');
const {dest, series, src, task, watch} = require('gulp');
const replace = require('gulp-replace');
const {series, task, watch} = require('gulp');
const {EOL} = require('os');
const {delimiter, normalize, resolve} = require('path');

// Initialize the build system.
const _path = 'PATH' in process.env ? process.env.PATH : '';
const _path = process.env.PATH ?? '';
const _vendor = resolve('node_modules/.bin');
if (!_path.includes(_vendor)) process.env.PATH = `${_vendor}${delimiter}${_path}`;

/** Builds the project. */
const esmRegex = /(export|import)\s+(.+)\s+from\s+'((?!.*\.js)\.[^']+)'/g;
task('build:fix', () => src('lib/**/*.js').pipe(replace(esmRegex, "$1 $2 from '$3.js'")).pipe(dest('lib')));
task('build:js', () => _exec('tsc', ['--project', 'src/tsconfig.json']));
task('build', series('build:js', 'build:fix'));
task('build', () => _exec('tsc', ['--project', 'src/tsconfig.json']));

/** Deletes all generated files and reset any saved state. */
task('clean', () => del(['build', 'doc/api', 'lib', 'var/**/*', 'web']));
Expand Down
2 changes: 1 addition & 1 deletion lib/author.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonObject } from './json';
import { JsonObject } from './json.js';
/** Represents the author of a comment. */
export declare class Author {
ipAddress: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/blog.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonObject } from './json';
import { JsonObject } from './json.js';
/** Represents the front page or home URL transmitted when making requests. */
export declare class Blog {
url?: URL | undefined;
Expand Down
4 changes: 2 additions & 2 deletions lib/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
import { Blog } from './blog';
import { Comment } from './comment';
import { Blog } from './blog.js';
import { Comment } from './comment.js';
/** Specifies the result of a comment check. */
export declare enum CheckResult {
/** The comment is not a spam (i.e. a ham). */
Expand Down
4 changes: 2 additions & 2 deletions lib/comment.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Author } from './author';
import { JsonObject } from './json';
import { Author } from './author.js';
import { JsonObject } from './json.js';
/** Represents a comment submitted by an author. */
export declare class Comment {
author?: Author | undefined;
Expand Down
10 changes: 5 additions & 5 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './author';
export * from './blog';
export * from './client';
export * from './comment';
export * from './json';
export * from './author.js';
export * from './blog.js';
export * from './client.js';
export * from './comment.js';
export * from './json.js';
4 changes: 2 additions & 2 deletions share/api.http
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
POST {{baseUrl}}/comment-check
Content-Type: application/x-www-form-urlencoded

blog=https%3A%2F%2Fdev.belin.io%2Fakismet.js&comment_author=Akismet&comment_author_url=https%3A%2F%2Fdev.belin.io%2Fakismet.js&comment_content=I'm%20testing%20out%20the%20Service%20API.&comment_type=comment&is_test=true&referrer=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40cedx%2Fakismet&user_agent=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64%3B%20rv%3A70.0)%20Gecko%2F20100101%20Firefox%2F70.0&user_ip=192.168.0.1&user_role=administrator
blog=https%3A%2F%2Fdocs.belin.io%2Fakismet.js&comment_author=Akismet&comment_author_url=https%3A%2F%2Fdocs.belin.io%2Fakismet.js&comment_content=I'm%20testing%20out%20the%20Service%20API.&comment_type=comment&is_test=true&referrer=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40cedx%2Fakismet&user_agent=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64%3B%20rv%3A70.0)%20Gecko%2F20100101%20Firefox%2F70.0&user_ip=192.168.0.1&user_role=administrator

###

// It should return `true` for invalid comment (e.g. spam).
POST {{baseUrl}}/comment-check
Content-Type: application/x-www-form-urlencoded

blog=https%3A%2F%2Fdev.belin.io%2Fakismet.js&comment_author=viagra-test-123&comment_content=Spam!&comment_type=trackback&comment_author_email=akismet-guaranteed-spam%40example.com&is_test=true&user_ip=127.0.0.1&user_agent=Spam%20Bot%2F6.6.6
blog=https%3A%2F%2Fdocs.belin.io%2Fakismet.js&comment_author=viagra-test-123&comment_content=Spam!&comment_type=trackback&comment_author_email=akismet-guaranteed-spam%40example.com&is_test=true&user_ip=127.0.0.1&user_agent=Spam%20Bot%2F6.6.6

###
2 changes: 1 addition & 1 deletion src/author.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {JsonObject} from './json';
import {JsonObject} from './json.js';

/** Represents the author of a comment. */
export class Author {
Expand Down
2 changes: 1 addition & 1 deletion src/blog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {JsonObject} from './json';
import {JsonObject} from './json.js';

/** Represents the front page or home URL transmitted when making requests. */
export class Blog {
Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {EventEmitter} from 'events';
import fetch, {Response} from 'node-fetch';
import {Blog} from './blog';
import {Comment} from './comment';
import {JsonObject} from './json';
import {packageVersion} from './version.g';
import {Blog} from './blog.js';
import {Comment} from './comment.js';
import {JsonObject} from './json.js';
import {packageVersion} from './version.g.js';

/** Specifies the result of a comment check. */
export enum CheckResult {
Expand Down
4 changes: 2 additions & 2 deletions src/comment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Author} from './author';
import {JsonObject} from './json';
import {Author} from './author.js';
import {JsonObject} from './json.js';

/** Represents a comment submitted by an author. */
export class Comment {
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './author';
export * from './blog';
export * from './client';
export * from './comment';
export * from './json';
export * from './author.js';
export * from './blog.js';
export * from './client.js';
export * from './comment.js';
export * from './json.js';
2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"moduleResolution": "node",
"outDir": "../lib",
"strict": true,
"target": "es2019",
"target": "es2020",
"tsBuildInfoFile": "../var/tsbuild.json"
}
}

0 comments on commit 704ef8e

Please sign in to comment.